IScsiConfig.c 129 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934
  1. /** @file
  2. Helper functions for configuring or getting the parameters relating to iSCSI.
  3. Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "IScsiImpl.h"
  7. CHAR16 mVendorStorageName[] = L"ISCSI_CONFIG_IFR_NVDATA";
  8. ISCSI_FORM_CALLBACK_INFO *mCallbackInfo = NULL;
  9. HII_VENDOR_DEVICE_PATH mIScsiHiiVendorDevicePath = {
  10. {
  11. {
  12. HARDWARE_DEVICE_PATH,
  13. HW_VENDOR_DP,
  14. {
  15. (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
  16. (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
  17. }
  18. },
  19. ISCSI_CONFIG_GUID
  20. },
  21. {
  22. END_DEVICE_PATH_TYPE,
  23. END_ENTIRE_DEVICE_PATH_SUBTYPE,
  24. {
  25. (UINT8) (END_DEVICE_PATH_LENGTH),
  26. (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
  27. }
  28. }
  29. };
  30. /**
  31. Convert the IP address into a dotted string.
  32. @param[in] Ip The IP address.
  33. @param[in] Ipv6Flag Indicates whether the IP address is version 4 or version 6.
  34. @param[out] Str The formatted IP string.
  35. **/
  36. VOID
  37. IScsiIpToStr (
  38. IN EFI_IP_ADDRESS *Ip,
  39. IN BOOLEAN Ipv6Flag,
  40. OUT CHAR16 *Str
  41. )
  42. {
  43. EFI_IPv4_ADDRESS *Ip4;
  44. EFI_IPv6_ADDRESS *Ip6;
  45. UINTN Index;
  46. BOOLEAN Short;
  47. UINTN Number;
  48. CHAR16 FormatString[8];
  49. if (!Ipv6Flag) {
  50. Ip4 = &Ip->v4;
  51. UnicodeSPrint (
  52. Str,
  53. (UINTN) 2 * IP4_STR_MAX_SIZE,
  54. L"%d.%d.%d.%d",
  55. (UINTN) Ip4->Addr[0],
  56. (UINTN) Ip4->Addr[1],
  57. (UINTN) Ip4->Addr[2],
  58. (UINTN) Ip4->Addr[3]
  59. );
  60. return ;
  61. }
  62. Ip6 = &Ip->v6;
  63. Short = FALSE;
  64. for (Index = 0; Index < 15; Index = Index + 2) {
  65. if (!Short &&
  66. Index % 2 == 0 &&
  67. Ip6->Addr[Index] == 0 &&
  68. Ip6->Addr[Index + 1] == 0
  69. ) {
  70. //
  71. // Deal with the case of ::.
  72. //
  73. if (Index == 0) {
  74. *Str = L':';
  75. *(Str + 1) = L':';
  76. Str = Str + 2;
  77. } else {
  78. *Str = L':';
  79. Str = Str + 1;
  80. }
  81. while ((Index < 15) && (Ip6->Addr[Index] == 0) && (Ip6->Addr[Index + 1] == 0)) {
  82. Index = Index + 2;
  83. }
  84. Short = TRUE;
  85. if (Index == 16) {
  86. //
  87. // :: is at the end of the address.
  88. //
  89. *Str = L'\0';
  90. break;
  91. }
  92. }
  93. ASSERT (Index < 15);
  94. if (Ip6->Addr[Index] == 0) {
  95. Number = UnicodeSPrint (Str, 2 * IP_STR_MAX_SIZE, L"%x:", (UINTN) Ip6->Addr[Index + 1]);
  96. } else {
  97. if (Ip6->Addr[Index + 1] < 0x10) {
  98. CopyMem (FormatString, L"%x0%x:", StrSize (L"%x0%x:"));
  99. } else {
  100. CopyMem (FormatString, L"%x%x:", StrSize (L"%x%x:"));
  101. }
  102. Number = UnicodeSPrint (
  103. Str,
  104. 2 * IP_STR_MAX_SIZE,
  105. (CONST CHAR16 *) FormatString,
  106. (UINTN) Ip6->Addr[Index],
  107. (UINTN) Ip6->Addr[Index + 1]
  108. );
  109. }
  110. Str = Str + Number;
  111. if (Index + 2 == 16) {
  112. *Str = L'\0';
  113. if (*(Str - 1) == L':') {
  114. *(Str - 1) = L'\0';
  115. }
  116. }
  117. }
  118. }
  119. /**
  120. Check whether the input IP address is valid.
  121. @param[in] Ip The IP address.
  122. @param[in] IpMode Indicates iSCSI running on IP4 or IP6 stack.
  123. @retval TRUE The input IP address is valid.
  124. @retval FALSE Otherwise
  125. **/
  126. BOOLEAN
  127. IpIsUnicast (
  128. IN EFI_IP_ADDRESS *Ip,
  129. IN UINT8 IpMode
  130. )
  131. {
  132. if (IpMode == IP_MODE_IP4) {
  133. if (IP4_IS_UNSPECIFIED (NTOHL (Ip->Addr[0])) || IP4_IS_LOCAL_BROADCAST (NTOHL (Ip->Addr[0]))) {
  134. return FALSE;
  135. }
  136. return TRUE;
  137. } else if (IpMode == IP_MODE_IP6) {
  138. return NetIp6IsValidUnicast (&Ip->v6);
  139. } else {
  140. DEBUG ((DEBUG_ERROR, "IpMode %d is invalid when configuring the iSCSI target IP!\n", IpMode));
  141. return FALSE;
  142. }
  143. }
  144. /**
  145. Parse IsId in string format and convert it to binary.
  146. @param[in] String The buffer of the string to be parsed.
  147. @param[in, out] IsId The buffer to store IsId.
  148. @retval EFI_SUCCESS The operation finished successfully.
  149. @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
  150. **/
  151. EFI_STATUS
  152. IScsiParseIsIdFromString (
  153. IN CONST CHAR16 *String,
  154. IN OUT UINT8 *IsId
  155. )
  156. {
  157. UINT8 Index;
  158. CHAR16 *IsIdStr;
  159. CHAR16 TempStr[3];
  160. UINTN NodeVal;
  161. CHAR16 PortString[ISCSI_NAME_IFR_MAX_SIZE];
  162. EFI_INPUT_KEY Key;
  163. if ((String == NULL) || (IsId == NULL)) {
  164. return EFI_INVALID_PARAMETER;
  165. }
  166. IsIdStr = (CHAR16 *) String;
  167. if (StrLen (IsIdStr) != 6 && StrLen (IsIdStr) != 12) {
  168. UnicodeSPrint (
  169. PortString,
  170. (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
  171. L"Error! Only last 3 bytes are configurable, please input 6 hex numbers for last 3 bytes only or 12 hex numbers for full SSID!\n"
  172. );
  173. CreatePopUp (
  174. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  175. &Key,
  176. PortString,
  177. NULL
  178. );
  179. return EFI_INVALID_PARAMETER;
  180. }
  181. if (StrLen (IsIdStr) == 12) {
  182. IsIdStr += 6;
  183. }
  184. for (Index = 3; Index < 6; Index++) {
  185. CopyMem (TempStr, IsIdStr, sizeof (TempStr));
  186. TempStr[2] = L'\0';
  187. //
  188. // Convert the string to IsId. StrHexToUintn stops at the first character
  189. // that is not a valid hex character, '\0' here.
  190. //
  191. NodeVal = StrHexToUintn (TempStr);
  192. IsId[Index] = (UINT8) NodeVal;
  193. IsIdStr = IsIdStr + 2;
  194. }
  195. return EFI_SUCCESS;
  196. }
  197. /**
  198. Convert IsId from binary to string format.
  199. @param[out] String The buffer to store the converted string.
  200. @param[in] IsId The buffer to store IsId.
  201. @retval EFI_SUCCESS The string converted successfully.
  202. @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
  203. **/
  204. EFI_STATUS
  205. IScsiConvertIsIdToString (
  206. OUT CHAR16 *String,
  207. IN UINT8 *IsId
  208. )
  209. {
  210. UINT8 Index;
  211. UINTN Number;
  212. if ((String == NULL) || (IsId == NULL)) {
  213. return EFI_INVALID_PARAMETER;
  214. }
  215. for (Index = 0; Index < 6; Index++) {
  216. if (IsId[Index] <= 0xF) {
  217. Number = UnicodeSPrint (
  218. String,
  219. 2 * ISID_CONFIGURABLE_STORAGE,
  220. L"0%X",
  221. (UINTN) IsId[Index]
  222. );
  223. } else {
  224. Number = UnicodeSPrint (
  225. String,
  226. 2 * ISID_CONFIGURABLE_STORAGE,
  227. L"%X",
  228. (UINTN) IsId[Index]
  229. );
  230. }
  231. String = String + Number;
  232. }
  233. *String = L'\0';
  234. return EFI_SUCCESS;
  235. }
  236. /**
  237. Get the Offset value specified by the input String.
  238. @param[in] Configuration A null-terminated Unicode string in
  239. <ConfigString> format.
  240. @param[in] String The string is "&OFFSET=".
  241. @param[out] Value The Offset value.
  242. @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
  243. structures.
  244. @retval EFI_SUCCESS Value of <Number> is outputted in Number
  245. successfully.
  246. **/
  247. EFI_STATUS
  248. IScsiGetValue (
  249. IN CONST EFI_STRING Configuration,
  250. IN CHAR16 *String,
  251. OUT UINTN *Value
  252. )
  253. {
  254. CHAR16 *StringPtr;
  255. CHAR16 *TmpPtr;
  256. CHAR16 *Str;
  257. CHAR16 TmpStr[2];
  258. UINTN Length;
  259. UINTN Len;
  260. UINTN Index;
  261. UINT8 *Buf;
  262. UINT8 DigitUint8;
  263. EFI_STATUS Status;
  264. //
  265. // Get Value.
  266. //
  267. Buf = NULL;
  268. StringPtr = StrStr (Configuration, String);
  269. ASSERT(StringPtr != NULL);
  270. StringPtr += StrLen (String);
  271. TmpPtr = StringPtr;
  272. while (*StringPtr != L'\0' && *StringPtr != L'&') {
  273. StringPtr ++;
  274. }
  275. Length = StringPtr - TmpPtr;
  276. Len = Length + 1;
  277. Str = AllocateZeroPool (Len * sizeof (CHAR16));
  278. if (Str == NULL) {
  279. Status = EFI_OUT_OF_RESOURCES;
  280. goto Exit;
  281. }
  282. CopyMem (Str, TmpPtr, Len * sizeof (CHAR16));
  283. *(Str + Length) = L'\0';
  284. Len = (Len + 1) / 2;
  285. Buf = (UINT8 *) AllocateZeroPool (Len);
  286. if (Buf == NULL) {
  287. Status = EFI_OUT_OF_RESOURCES;
  288. goto Exit;
  289. }
  290. ZeroMem (TmpStr, sizeof (TmpStr));
  291. for (Index = 0; Index < Length; Index ++) {
  292. TmpStr[0] = Str[Length - Index - 1];
  293. DigitUint8 = (UINT8) StrHexToUint64 (TmpStr);
  294. if ((Index & 1) == 0) {
  295. Buf [Index/2] = DigitUint8;
  296. } else {
  297. Buf [Index/2] = (UINT8) ((DigitUint8 << 4) + Buf [Index/2]);
  298. }
  299. }
  300. *Value = 0;
  301. CopyMem (
  302. Value,
  303. Buf,
  304. (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)
  305. );
  306. FreePool (Buf);
  307. Status = EFI_SUCCESS;
  308. Exit:
  309. if (Str != NULL) {
  310. FreePool (Str);
  311. }
  312. return Status;
  313. }
  314. /**
  315. Get the attempt config data from global structure by the ConfigIndex.
  316. @param[in] AttemptConfigIndex The unique index indicates the attempt.
  317. @return Pointer to the attempt config data.
  318. @retval NULL The attempt configuration data cannot be found.
  319. **/
  320. ISCSI_ATTEMPT_CONFIG_NVDATA *
  321. IScsiConfigGetAttemptByConfigIndex (
  322. IN UINT8 AttemptConfigIndex
  323. )
  324. {
  325. LIST_ENTRY *Entry;
  326. ISCSI_ATTEMPT_CONFIG_NVDATA *Attempt;
  327. NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {
  328. Attempt = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
  329. if (Attempt->AttemptConfigIndex == AttemptConfigIndex) {
  330. return Attempt;
  331. }
  332. }
  333. return NULL;
  334. }
  335. /**
  336. Get the existing attempt config data from global structure by the NicIndex.
  337. @param[in] NewAttempt The created new attempt
  338. @param[in] IScsiMode The IScsi Mode of the new attempt, Enabled or
  339. Enabled for MPIO.
  340. @return Pointer to the existing attempt config data which
  341. has the same NICIndex as the new created attempt.
  342. @retval NULL The attempt with NicIndex does not exist.
  343. **/
  344. ISCSI_ATTEMPT_CONFIG_NVDATA *
  345. IScsiConfigGetAttemptByNic (
  346. IN ISCSI_ATTEMPT_CONFIG_NVDATA *NewAttempt,
  347. IN UINT8 IScsiMode
  348. )
  349. {
  350. LIST_ENTRY *Entry;
  351. ISCSI_ATTEMPT_CONFIG_NVDATA *Attempt;
  352. NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {
  353. Attempt = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
  354. if (Attempt != NewAttempt && Attempt->NicIndex == NewAttempt->NicIndex &&
  355. Attempt->SessionConfigData.Enabled == IScsiMode) {
  356. return Attempt;
  357. }
  358. }
  359. return NULL;
  360. }
  361. /**
  362. Extract the Index of the attempt list.
  363. @param[in] AttemptNameList The Name list of the Attempts.
  364. @param[out] AttemptIndexList The Index list of the Attempts.
  365. @param[in] IsAddAttempts If TRUE, Indicates add one or more attempts.
  366. If FALSE, Indicates delete attempts or change attempt order.
  367. @retval EFI_SUCCESS The Attempt list is valid.
  368. @retval EFI_INVALID_PARAMETERS The Attempt List is invalid.
  369. **/
  370. EFI_STATUS
  371. IScsiGetAttemptIndexList (
  372. IN CHAR16 *AttemptNameList,
  373. OUT UINT8 *AttemptIndexList,
  374. IN BOOLEAN IsAddAttempts
  375. )
  376. {
  377. ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;
  378. CHAR16 *AttemptStr;
  379. UINT8 AttemptIndex;
  380. UINTN Len;
  381. UINTN Index;
  382. Index = 0;
  383. if ((AttemptNameList == NULL) || (*AttemptNameList == L'\0')) {
  384. return EFI_INVALID_PARAMETER;
  385. }
  386. AttemptStr = AttemptNameList;
  387. Len = StrLen (L"attempt:");
  388. while (*AttemptStr != L'\0') {
  389. AttemptStr = StrStr (AttemptStr, L"attempt:");
  390. if (AttemptStr == NULL) {
  391. return EFI_INVALID_PARAMETER;
  392. }
  393. AttemptStr += Len;
  394. AttemptIndex = (UINT8)(*AttemptStr - L'0');
  395. AttemptConfigData = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
  396. if (IsAddAttempts) {
  397. if ((AttemptConfigData != NULL) || ((AttemptIndex) > PcdGet8 (PcdMaxIScsiAttemptNumber))) {
  398. return EFI_INVALID_PARAMETER;
  399. }
  400. } else {
  401. if (AttemptConfigData == NULL) {
  402. return EFI_INVALID_PARAMETER;
  403. }
  404. }
  405. AttemptIndexList[Index] = AttemptIndex;
  406. Index ++;
  407. AttemptStr += 2;
  408. }
  409. return EFI_SUCCESS;
  410. }
  411. /**
  412. Convert the iSCSI configuration data into the IFR data.
  413. @param[in] Attempt The iSCSI attempt config data.
  414. @param[in, out] IfrNvData The IFR nv data.
  415. **/
  416. VOID
  417. IScsiConvertAttemptConfigDataToIfrNvData (
  418. IN ISCSI_ATTEMPT_CONFIG_NVDATA *Attempt,
  419. IN OUT ISCSI_CONFIG_IFR_NVDATA *IfrNvData
  420. )
  421. {
  422. ISCSI_SESSION_CONFIG_NVDATA *SessionConfigData;
  423. ISCSI_CHAP_AUTH_CONFIG_NVDATA *AuthConfigData;
  424. EFI_IP_ADDRESS Ip;
  425. BOOLEAN DnsMode;
  426. //
  427. // Normal session configuration parameters.
  428. //
  429. SessionConfigData = &Attempt->SessionConfigData;
  430. IfrNvData->Enabled = SessionConfigData->Enabled;
  431. IfrNvData->IpMode = SessionConfigData->IpMode;
  432. DnsMode = SessionConfigData->DnsMode;
  433. IfrNvData->InitiatorInfoFromDhcp = SessionConfigData->InitiatorInfoFromDhcp;
  434. IfrNvData->TargetInfoFromDhcp = SessionConfigData->TargetInfoFromDhcp;
  435. IfrNvData->TargetPort = SessionConfigData->TargetPort;
  436. if (IfrNvData->IpMode == IP_MODE_IP4) {
  437. CopyMem (&Ip.v4, &SessionConfigData->LocalIp, sizeof (EFI_IPv4_ADDRESS));
  438. IScsiIpToStr (&Ip, FALSE, IfrNvData->LocalIp);
  439. CopyMem (&Ip.v4, &SessionConfigData->SubnetMask, sizeof (EFI_IPv4_ADDRESS));
  440. IScsiIpToStr (&Ip, FALSE, IfrNvData->SubnetMask);
  441. CopyMem (&Ip.v4, &SessionConfigData->Gateway, sizeof (EFI_IPv4_ADDRESS));
  442. IScsiIpToStr (&Ip, FALSE, IfrNvData->Gateway);
  443. ZeroMem (IfrNvData->TargetIp, sizeof (IfrNvData->TargetIp));
  444. if (SessionConfigData->TargetIp.v4.Addr[0] != '\0') {
  445. CopyMem (&Ip.v4, &SessionConfigData->TargetIp, sizeof (EFI_IPv4_ADDRESS));
  446. IScsiIpToStr (&Ip, FALSE, IfrNvData->TargetIp);
  447. }
  448. } else if (IfrNvData->IpMode == IP_MODE_IP6) {
  449. ZeroMem (IfrNvData->TargetIp, sizeof (IfrNvData->TargetIp));
  450. if (SessionConfigData->TargetIp.v6.Addr[0] != '\0') {
  451. IP6_COPY_ADDRESS (&Ip.v6, &SessionConfigData->TargetIp);
  452. IScsiIpToStr (&Ip, TRUE, IfrNvData->TargetIp);
  453. }
  454. }
  455. AsciiStrToUnicodeStrS (
  456. SessionConfigData->TargetName,
  457. IfrNvData->TargetName,
  458. sizeof (IfrNvData->TargetName) / sizeof (IfrNvData->TargetName[0])
  459. );
  460. if (DnsMode) {
  461. AsciiStrToUnicodeStrS (
  462. SessionConfigData->TargetUrl,
  463. IfrNvData->TargetIp,
  464. sizeof (IfrNvData->TargetIp) / sizeof (IfrNvData->TargetIp[0])
  465. );
  466. }
  467. IScsiLunToUnicodeStr (SessionConfigData->BootLun, IfrNvData->BootLun);
  468. IScsiConvertIsIdToString (IfrNvData->IsId, SessionConfigData->IsId);
  469. IfrNvData->ConnectRetryCount = SessionConfigData->ConnectRetryCount;
  470. IfrNvData->ConnectTimeout = SessionConfigData->ConnectTimeout;
  471. //
  472. // Authentication parameters.
  473. //
  474. IfrNvData->AuthenticationType = Attempt->AuthenticationType;
  475. if (IfrNvData->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {
  476. AuthConfigData = &Attempt->AuthConfigData.CHAP;
  477. IfrNvData->CHAPType = AuthConfigData->CHAPType;
  478. AsciiStrToUnicodeStrS (
  479. AuthConfigData->CHAPName,
  480. IfrNvData->CHAPName,
  481. sizeof (IfrNvData->CHAPName) / sizeof (IfrNvData->CHAPName[0])
  482. );
  483. AsciiStrToUnicodeStrS (
  484. AuthConfigData->CHAPSecret,
  485. IfrNvData->CHAPSecret,
  486. sizeof (IfrNvData->CHAPSecret) / sizeof (IfrNvData->CHAPSecret[0])
  487. );
  488. AsciiStrToUnicodeStrS (
  489. AuthConfigData->ReverseCHAPName,
  490. IfrNvData->ReverseCHAPName,
  491. sizeof (IfrNvData->ReverseCHAPName) / sizeof (IfrNvData->ReverseCHAPName[0])
  492. );
  493. AsciiStrToUnicodeStrS (
  494. AuthConfigData->ReverseCHAPSecret,
  495. IfrNvData->ReverseCHAPSecret,
  496. sizeof (IfrNvData->ReverseCHAPSecret) / sizeof (IfrNvData->ReverseCHAPSecret[0])
  497. );
  498. }
  499. //
  500. // Other parameters.
  501. //
  502. AsciiStrToUnicodeStrS (
  503. Attempt->AttemptName,
  504. IfrNvData->AttemptName,
  505. sizeof (IfrNvData->AttemptName) / sizeof (IfrNvData->AttemptName[0])
  506. );
  507. }
  508. /**
  509. Convert the iSCSI configuration data into the IFR data Which will be used
  510. to extract the iSCSI Keyword configuration in <ConfigAltResp> format.
  511. @param[in, out] IfrNvData The IFR nv data.
  512. **/
  513. VOID
  514. EFIAPI
  515. IScsiConvertAttemptConfigDataToIfrNvDataByKeyword (
  516. IN OUT ISCSI_CONFIG_IFR_NVDATA *IfrNvData
  517. )
  518. {
  519. LIST_ENTRY *Entry;
  520. ISCSI_ATTEMPT_CONFIG_NVDATA *Attempt;
  521. ISCSI_SESSION_CONFIG_NVDATA *SessionConfigData;
  522. ISCSI_CHAP_AUTH_CONFIG_NVDATA *AuthConfigData;
  523. CHAR16 AttemptNameList[ATTEMPT_NAME_LIST_SIZE];
  524. ISCSI_NIC_INFO *NicInfo;
  525. CHAR16 MacString[ISCSI_MAX_MAC_STRING_LEN];
  526. EFI_IP_ADDRESS Ip;
  527. UINTN Index;
  528. UINTN StringLen;
  529. NicInfo = NULL;
  530. ZeroMem (AttemptNameList, sizeof (AttemptNameList));
  531. if ((mPrivate != NULL) && (mPrivate->AttemptCount != 0)) {
  532. NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {
  533. Attempt = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
  534. //
  535. // Normal session configuration parameters.
  536. //
  537. SessionConfigData = &Attempt->SessionConfigData;
  538. ASSERT ((Attempt->AttemptConfigIndex > 0) && (Attempt->AttemptConfigIndex <= FixedPcdGet8 (PcdMaxIScsiAttemptNumber)));
  539. Index = Attempt->AttemptConfigIndex - 1;
  540. //
  541. // Save the attempt to AttemptNameList as Attempt:1 Attempt:2
  542. //
  543. AsciiStrToUnicodeStrS (
  544. Attempt->AttemptName,
  545. AttemptNameList + StrLen (AttemptNameList),
  546. ATTEMPT_NAME_LIST_SIZE - StrLen (AttemptNameList)
  547. );
  548. StringLen = StrLen (AttemptNameList);
  549. ASSERT (StringLen > 2);
  550. *(AttemptNameList + StringLen - 2) = L':';
  551. *(AttemptNameList + StringLen) = L' ';
  552. AsciiStrToUnicodeStrS (
  553. Attempt->AttemptName,
  554. IfrNvData->ISCSIAttemptName + ATTEMPT_NAME_SIZE * Index,
  555. ATTEMPT_NAME_LIST_SIZE - ATTEMPT_NAME_SIZE * Index
  556. );
  557. IfrNvData->ISCSIBootEnableList[Index] = SessionConfigData->Enabled;
  558. IfrNvData->ISCSIIpAddressTypeList[Index] = SessionConfigData->IpMode;
  559. IfrNvData->ISCSIInitiatorInfoViaDHCP[Index] = SessionConfigData->InitiatorInfoFromDhcp;
  560. IfrNvData->ISCSITargetInfoViaDHCP[Index] = SessionConfigData->TargetInfoFromDhcp;
  561. IfrNvData->ISCSIConnectRetry[Index] = SessionConfigData->ConnectRetryCount;
  562. IfrNvData->ISCSIConnectTimeout[Index] = SessionConfigData->ConnectTimeout;
  563. IfrNvData->ISCSITargetTcpPort[Index] = SessionConfigData->TargetPort;
  564. if (SessionConfigData->IpMode == IP_MODE_IP4) {
  565. CopyMem (&Ip.v4, &SessionConfigData->LocalIp, sizeof (EFI_IPv4_ADDRESS));
  566. IScsiIpToStr (&Ip, FALSE, IfrNvData->Keyword[Index].ISCSIInitiatorIpAddress);
  567. CopyMem (&Ip.v4, &SessionConfigData->SubnetMask, sizeof (EFI_IPv4_ADDRESS));
  568. IScsiIpToStr (&Ip, FALSE, IfrNvData->Keyword[Index].ISCSIInitiatorNetmask);
  569. CopyMem (&Ip.v4, &SessionConfigData->Gateway, sizeof (EFI_IPv4_ADDRESS));
  570. IScsiIpToStr (&Ip, FALSE, IfrNvData->Keyword[Index].ISCSIInitiatorGateway);
  571. if (SessionConfigData->TargetIp.v4.Addr[0] != '\0') {
  572. CopyMem (&Ip.v4, &SessionConfigData->TargetIp, sizeof (EFI_IPv4_ADDRESS));
  573. IScsiIpToStr (&Ip, FALSE, IfrNvData->Keyword[Index].ISCSITargetIpAddress);
  574. }
  575. } else if (SessionConfigData->IpMode == IP_MODE_IP6) {
  576. ZeroMem (IfrNvData->Keyword[Index].ISCSITargetIpAddress, sizeof (IfrNvData->TargetIp));
  577. if (SessionConfigData->TargetIp.v6.Addr[0] != '\0') {
  578. IP6_COPY_ADDRESS (&Ip.v6, &SessionConfigData->TargetIp);
  579. IScsiIpToStr (&Ip, TRUE, IfrNvData->Keyword[Index].ISCSITargetIpAddress);
  580. }
  581. }
  582. AsciiStrToUnicodeStrS (
  583. SessionConfigData->TargetName,
  584. IfrNvData->Keyword[Index].ISCSITargetName,
  585. ISCSI_NAME_MAX_SIZE
  586. );
  587. if (SessionConfigData->DnsMode) {
  588. AsciiStrToUnicodeStrS (
  589. SessionConfigData->TargetUrl,
  590. IfrNvData->Keyword[Index].ISCSITargetIpAddress,
  591. sizeof (IfrNvData->Keyword[Index].ISCSITargetIpAddress) / sizeof (IfrNvData->Keyword[Index].ISCSITargetIpAddress[0])
  592. );
  593. }
  594. IScsiLunToUnicodeStr (SessionConfigData->BootLun, IfrNvData->Keyword[Index].ISCSILun);
  595. IScsiConvertIsIdToString (IfrNvData->Keyword[Index].ISCSIIsId, SessionConfigData->IsId);
  596. IfrNvData->ISCSIAuthenticationMethod[Index] = Attempt->AuthenticationType;
  597. if (Attempt->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {
  598. AuthConfigData = &Attempt->AuthConfigData.CHAP;
  599. IfrNvData->ISCSIChapType[Index] = AuthConfigData->CHAPType;
  600. AsciiStrToUnicodeStrS (
  601. AuthConfigData->CHAPName,
  602. IfrNvData->Keyword[Index].ISCSIChapUsername,
  603. ISCSI_CHAP_NAME_STORAGE
  604. );
  605. AsciiStrToUnicodeStrS (
  606. AuthConfigData->CHAPSecret,
  607. IfrNvData->Keyword[Index].ISCSIChapSecret,
  608. ISCSI_CHAP_SECRET_STORAGE
  609. );
  610. AsciiStrToUnicodeStrS (
  611. AuthConfigData->ReverseCHAPName,
  612. IfrNvData->Keyword[Index].ISCSIReverseChapUsername,
  613. ISCSI_CHAP_NAME_STORAGE
  614. );
  615. AsciiStrToUnicodeStrS (
  616. AuthConfigData->ReverseCHAPSecret,
  617. IfrNvData->Keyword[Index].ISCSIReverseChapSecret,
  618. ISCSI_CHAP_SECRET_STORAGE
  619. );
  620. }
  621. }
  622. CopyMem(IfrNvData->ISCSIDisplayAttemptList, AttemptNameList, ATTEMPT_NAME_LIST_SIZE);
  623. ZeroMem (IfrNvData->ISCSIMacAddr, sizeof (IfrNvData->ISCSIMacAddr));
  624. NET_LIST_FOR_EACH (Entry, &mPrivate->NicInfoList) {
  625. NicInfo = NET_LIST_USER_STRUCT (Entry, ISCSI_NIC_INFO, Link);
  626. IScsiMacAddrToStr (
  627. &NicInfo->PermanentAddress,
  628. NicInfo->HwAddressSize,
  629. NicInfo->VlanId,
  630. MacString
  631. );
  632. CopyMem (
  633. IfrNvData->ISCSIMacAddr + StrLen (IfrNvData->ISCSIMacAddr),
  634. MacString,
  635. StrLen (MacString) * sizeof (CHAR16)
  636. );
  637. *(IfrNvData->ISCSIMacAddr + StrLen (IfrNvData->ISCSIMacAddr)) = L'/';
  638. }
  639. StringLen = StrLen (IfrNvData->ISCSIMacAddr);
  640. if (StringLen > 0) {
  641. *(IfrNvData->ISCSIMacAddr + StringLen - 1) = L'\0';
  642. }
  643. }
  644. }
  645. /**
  646. Convert the IFR data to iSCSI configuration data.
  647. @param[in] IfrNvData Point to ISCSI_CONFIG_IFR_NVDATA.
  648. @param[in, out] Attempt The iSCSI attempt config data.
  649. @retval EFI_INVALID_PARAMETER Any input or configured parameter is invalid.
  650. @retval EFI_NOT_FOUND Cannot find the corresponding variable.
  651. @retval EFI_OUT_OF_RESOURCES The operation is failed due to lack of resources.
  652. @retval EFI_ABORTED The operation is aborted.
  653. @retval EFI_SUCCESS The operation is completed successfully.
  654. **/
  655. EFI_STATUS
  656. IScsiConvertIfrNvDataToAttemptConfigData (
  657. IN ISCSI_CONFIG_IFR_NVDATA *IfrNvData,
  658. IN OUT ISCSI_ATTEMPT_CONFIG_NVDATA *Attempt
  659. )
  660. {
  661. EFI_IP_ADDRESS HostIp;
  662. EFI_IP_ADDRESS SubnetMask;
  663. EFI_IP_ADDRESS Gateway;
  664. CHAR16 *MacString;
  665. CHAR16 *AttemptName1;
  666. CHAR16 *AttemptName2;
  667. ISCSI_ATTEMPT_CONFIG_NVDATA *ExistAttempt;
  668. ISCSI_ATTEMPT_CONFIG_NVDATA *SameNicAttempt;
  669. CHAR16 IScsiMode[64];
  670. CHAR16 IpMode[64];
  671. ISCSI_NIC_INFO *NicInfo;
  672. EFI_INPUT_KEY Key;
  673. UINT8 *AttemptConfigOrder;
  674. UINTN AttemptConfigOrderSize;
  675. UINT8 *AttemptOrderTmp;
  676. UINTN TotalNumber;
  677. EFI_STATUS Status;
  678. if (IfrNvData == NULL || Attempt == NULL) {
  679. return EFI_INVALID_PARAMETER;
  680. }
  681. //
  682. // Update those fields which don't have INTERACTIVE attribute.
  683. //
  684. Attempt->SessionConfigData.ConnectRetryCount = IfrNvData->ConnectRetryCount;
  685. Attempt->SessionConfigData.ConnectTimeout = IfrNvData->ConnectTimeout;
  686. Attempt->SessionConfigData.IpMode = IfrNvData->IpMode;
  687. if (IfrNvData->IpMode < IP_MODE_AUTOCONFIG) {
  688. Attempt->SessionConfigData.InitiatorInfoFromDhcp = IfrNvData->InitiatorInfoFromDhcp;
  689. Attempt->SessionConfigData.TargetPort = IfrNvData->TargetPort;
  690. if (Attempt->SessionConfigData.TargetPort == 0) {
  691. Attempt->SessionConfigData.TargetPort = ISCSI_WELL_KNOWN_PORT;
  692. }
  693. Attempt->SessionConfigData.TargetInfoFromDhcp = IfrNvData->TargetInfoFromDhcp;
  694. }
  695. Attempt->AuthenticationType = IfrNvData->AuthenticationType;
  696. if (Attempt->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {
  697. Attempt->AuthConfigData.CHAP.CHAPType = IfrNvData->CHAPType;
  698. }
  699. //
  700. // Only do full parameter validation if iSCSI is enabled on this device.
  701. //
  702. if (IfrNvData->Enabled != ISCSI_DISABLED) {
  703. if (Attempt->SessionConfigData.ConnectTimeout < CONNECT_MIN_TIMEOUT) {
  704. CreatePopUp (
  705. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  706. &Key,
  707. L"Connection Establishing Timeout is less than minimum value 100ms.",
  708. NULL
  709. );
  710. return EFI_INVALID_PARAMETER;
  711. }
  712. //
  713. // Validate the address configuration of the Initiator if DHCP isn't
  714. // deployed.
  715. //
  716. if (!Attempt->SessionConfigData.InitiatorInfoFromDhcp) {
  717. CopyMem (&HostIp.v4, &Attempt->SessionConfigData.LocalIp, sizeof (HostIp.v4));
  718. CopyMem (&SubnetMask.v4, &Attempt->SessionConfigData.SubnetMask, sizeof (SubnetMask.v4));
  719. CopyMem (&Gateway.v4, &Attempt->SessionConfigData.Gateway, sizeof (Gateway.v4));
  720. if ((Gateway.Addr[0] != 0)) {
  721. if (SubnetMask.Addr[0] == 0) {
  722. CreatePopUp (
  723. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  724. &Key,
  725. L"Gateway address is set but subnet mask is zero.",
  726. NULL
  727. );
  728. return EFI_INVALID_PARAMETER;
  729. } else if (!IP4_NET_EQUAL (HostIp.Addr[0], Gateway.Addr[0], SubnetMask.Addr[0])) {
  730. CreatePopUp (
  731. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  732. &Key,
  733. L"Local IP and Gateway are not in the same subnet.",
  734. NULL
  735. );
  736. return EFI_INVALID_PARAMETER;
  737. }
  738. }
  739. }
  740. //
  741. // Validate target configuration if DHCP isn't deployed.
  742. //
  743. if (!Attempt->SessionConfigData.TargetInfoFromDhcp && Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) {
  744. if (!Attempt->SessionConfigData.DnsMode) {
  745. if (!IpIsUnicast (&Attempt->SessionConfigData.TargetIp, IfrNvData->IpMode)) {
  746. CreatePopUp (
  747. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  748. &Key,
  749. L"Target IP is invalid!",
  750. NULL
  751. );
  752. return EFI_INVALID_PARAMETER;
  753. }
  754. } else {
  755. if (Attempt->SessionConfigData.TargetUrl[0] == '\0') {
  756. CreatePopUp (
  757. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  758. &Key,
  759. L"iSCSI target Url should not be NULL!",
  760. NULL
  761. );
  762. return EFI_INVALID_PARAMETER;
  763. }
  764. }
  765. //
  766. // Validate iSCSI target name configuration again:
  767. // The format of iSCSI target name is already verified in IScsiFormCallback() when
  768. // user input the name; here we only check the case user does not input the name.
  769. //
  770. if (Attempt->SessionConfigData.TargetName[0] == '\0') {
  771. CreatePopUp (
  772. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  773. &Key,
  774. L"iSCSI target name is NULL!",
  775. NULL
  776. );
  777. return EFI_INVALID_PARAMETER;
  778. }
  779. }
  780. //
  781. // Validate the authentication info.
  782. //
  783. if (IfrNvData->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {
  784. if ((IfrNvData->CHAPName[0] == '\0') || (IfrNvData->CHAPSecret[0] == '\0')) {
  785. CreatePopUp (
  786. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  787. &Key,
  788. L"CHAP Name or CHAP Secret is invalid!",
  789. NULL
  790. );
  791. return EFI_INVALID_PARAMETER;
  792. }
  793. if ((IfrNvData->CHAPType == ISCSI_CHAP_MUTUAL) &&
  794. ((IfrNvData->ReverseCHAPName[0] == '\0') || (IfrNvData->ReverseCHAPSecret[0] == '\0'))
  795. ) {
  796. CreatePopUp (
  797. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  798. &Key,
  799. L"Reverse CHAP Name or Reverse CHAP Secret is invalid!",
  800. NULL
  801. );
  802. return EFI_INVALID_PARAMETER;
  803. }
  804. }
  805. //
  806. // Check whether this attempt uses NIC which is already used by existing attempt.
  807. //
  808. SameNicAttempt = IScsiConfigGetAttemptByNic (Attempt, IfrNvData->Enabled);
  809. if (SameNicAttempt != NULL) {
  810. AttemptName1 = (CHAR16 *) AllocateZeroPool (ATTEMPT_NAME_SIZE * sizeof (CHAR16));
  811. if (AttemptName1 == NULL) {
  812. return EFI_OUT_OF_RESOURCES;
  813. }
  814. AttemptName2 = (CHAR16 *) AllocateZeroPool (ATTEMPT_NAME_SIZE * sizeof (CHAR16));
  815. if (AttemptName2 == NULL) {
  816. FreePool (AttemptName1);
  817. return EFI_OUT_OF_RESOURCES;
  818. }
  819. AsciiStrToUnicodeStrS (Attempt->AttemptName, AttemptName1, ATTEMPT_NAME_SIZE);
  820. AsciiStrToUnicodeStrS (SameNicAttempt->AttemptName, AttemptName2, ATTEMPT_NAME_SIZE);
  821. UnicodeSPrint (
  822. mPrivate->PortString,
  823. (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
  824. L"Warning! Attempt \"%s\" uses same NIC as Attempt \"%s\".",
  825. AttemptName1,
  826. AttemptName2
  827. );
  828. CreatePopUp (
  829. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  830. &Key,
  831. mPrivate->PortString,
  832. NULL
  833. );
  834. FreePool (AttemptName1);
  835. FreePool (AttemptName2);
  836. }
  837. }
  838. //
  839. // Update the iSCSI Mode data and record it in attempt help info.
  840. //
  841. if (IfrNvData->Enabled == ISCSI_DISABLED) {
  842. UnicodeSPrint (IScsiMode, 64, L"Disabled");
  843. } else if (IfrNvData->Enabled == ISCSI_ENABLED) {
  844. UnicodeSPrint (IScsiMode, 64, L"Enabled");
  845. } else if (IfrNvData->Enabled == ISCSI_ENABLED_FOR_MPIO) {
  846. UnicodeSPrint (IScsiMode, 64, L"Enabled for MPIO");
  847. }
  848. if (IfrNvData->IpMode == IP_MODE_IP4) {
  849. UnicodeSPrint (IpMode, 64, L"IP4");
  850. } else if (IfrNvData->IpMode == IP_MODE_IP6) {
  851. UnicodeSPrint (IpMode, 64, L"IP6");
  852. } else if (IfrNvData->IpMode == IP_MODE_AUTOCONFIG) {
  853. UnicodeSPrint (IpMode, 64, L"Autoconfigure");
  854. }
  855. NicInfo = IScsiGetNicInfoByIndex (Attempt->NicIndex);
  856. if (NicInfo == NULL) {
  857. return EFI_NOT_FOUND;
  858. }
  859. MacString = (CHAR16 *) AllocateZeroPool (ISCSI_MAX_MAC_STRING_LEN * sizeof (CHAR16));
  860. if (MacString == NULL) {
  861. return EFI_OUT_OF_RESOURCES;
  862. }
  863. AsciiStrToUnicodeStrS (Attempt->MacString, MacString, ISCSI_MAX_MAC_STRING_LEN);
  864. UnicodeSPrint (
  865. mPrivate->PortString,
  866. (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
  867. L"MAC: %s, PFA: Bus %d | Dev %d | Func %d, iSCSI mode: %s, IP version: %s",
  868. MacString,
  869. NicInfo->BusNumber,
  870. NicInfo->DeviceNumber,
  871. NicInfo->FunctionNumber,
  872. IScsiMode,
  873. IpMode
  874. );
  875. Attempt->AttemptTitleHelpToken = HiiSetString (
  876. mCallbackInfo->RegisteredHandle,
  877. Attempt->AttemptTitleHelpToken,
  878. mPrivate->PortString,
  879. NULL
  880. );
  881. if (Attempt->AttemptTitleHelpToken == 0) {
  882. FreePool (MacString);
  883. return EFI_OUT_OF_RESOURCES;
  884. }
  885. //
  886. // Check whether this attempt is an existing one.
  887. //
  888. ExistAttempt = IScsiConfigGetAttemptByConfigIndex (Attempt->AttemptConfigIndex);
  889. if (ExistAttempt != NULL) {
  890. ASSERT (ExistAttempt == Attempt);
  891. if (IfrNvData->Enabled == ISCSI_DISABLED &&
  892. Attempt->SessionConfigData.Enabled != ISCSI_DISABLED) {
  893. //
  894. // User updates the Attempt from "Enabled"/"Enabled for MPIO" to "Disabled".
  895. //
  896. if (Attempt->SessionConfigData.Enabled == ISCSI_ENABLED_FOR_MPIO) {
  897. if (mPrivate->MpioCount < 1) {
  898. return EFI_ABORTED;
  899. }
  900. if (--mPrivate->MpioCount == 0) {
  901. mPrivate->EnableMpio = FALSE;
  902. }
  903. } else if (Attempt->SessionConfigData.Enabled == ISCSI_ENABLED) {
  904. if (mPrivate->SinglePathCount < 1) {
  905. return EFI_ABORTED;
  906. }
  907. mPrivate->SinglePathCount--;
  908. }
  909. } else if (IfrNvData->Enabled == ISCSI_ENABLED_FOR_MPIO &&
  910. Attempt->SessionConfigData.Enabled == ISCSI_ENABLED) {
  911. //
  912. // User updates the Attempt from "Enabled" to "Enabled for MPIO".
  913. //
  914. if (mPrivate->SinglePathCount < 1) {
  915. return EFI_ABORTED;
  916. }
  917. mPrivate->EnableMpio = TRUE;
  918. mPrivate->MpioCount++;
  919. mPrivate->SinglePathCount--;
  920. } else if (IfrNvData->Enabled == ISCSI_ENABLED &&
  921. Attempt->SessionConfigData.Enabled == ISCSI_ENABLED_FOR_MPIO) {
  922. //
  923. // User updates the Attempt from "Enabled for MPIO" to "Enabled".
  924. //
  925. if (mPrivate->MpioCount < 1) {
  926. return EFI_ABORTED;
  927. }
  928. if (--mPrivate->MpioCount == 0) {
  929. mPrivate->EnableMpio = FALSE;
  930. }
  931. mPrivate->SinglePathCount++;
  932. } else if (IfrNvData->Enabled != ISCSI_DISABLED &&
  933. Attempt->SessionConfigData.Enabled == ISCSI_DISABLED) {
  934. //
  935. // User updates the Attempt from "Disabled" to "Enabled"/"Enabled for MPIO".
  936. //
  937. if (IfrNvData->Enabled == ISCSI_ENABLED_FOR_MPIO) {
  938. mPrivate->EnableMpio = TRUE;
  939. mPrivate->MpioCount++;
  940. } else if (IfrNvData->Enabled == ISCSI_ENABLED) {
  941. mPrivate->SinglePathCount++;
  942. }
  943. }
  944. } else if (ExistAttempt == NULL) {
  945. //
  946. // When a new attempt is created, pointer of the attempt is saved to
  947. // mCallbackInfo->Current in IScsiConfigProcessDefault. If input Attempt
  948. // does not match any existing attempt, it should be a new created attempt.
  949. // Save it to system now.
  950. //
  951. //
  952. // Save current order number for this attempt.
  953. //
  954. AttemptConfigOrder = IScsiGetVariableAndSize (
  955. L"AttemptOrder",
  956. &gIScsiConfigGuid,
  957. &AttemptConfigOrderSize
  958. );
  959. TotalNumber = AttemptConfigOrderSize / sizeof (UINT8);
  960. TotalNumber++;
  961. //
  962. // Append the new created attempt order to the end.
  963. //
  964. AttemptOrderTmp = AllocateZeroPool (TotalNumber * sizeof (UINT8));
  965. if (AttemptOrderTmp == NULL) {
  966. if (AttemptConfigOrder != NULL) {
  967. FreePool (AttemptConfigOrder);
  968. }
  969. return EFI_OUT_OF_RESOURCES;
  970. }
  971. if (AttemptConfigOrder != NULL) {
  972. CopyMem (AttemptOrderTmp, AttemptConfigOrder, AttemptConfigOrderSize);
  973. FreePool (AttemptConfigOrder);
  974. }
  975. AttemptOrderTmp[TotalNumber - 1] = Attempt->AttemptConfigIndex;
  976. AttemptConfigOrder = AttemptOrderTmp;
  977. AttemptConfigOrderSize = TotalNumber * sizeof (UINT8);
  978. Status = gRT->SetVariable (
  979. L"AttemptOrder",
  980. &gIScsiConfigGuid,
  981. EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
  982. AttemptConfigOrderSize,
  983. AttemptConfigOrder
  984. );
  985. FreePool (AttemptConfigOrder);
  986. if (EFI_ERROR (Status)) {
  987. return Status;
  988. }
  989. //
  990. // Insert new created attempt to array.
  991. //
  992. InsertTailList (&mPrivate->AttemptConfigs, &Attempt->Link);
  993. mPrivate->AttemptCount++;
  994. if (IfrNvData->Enabled == ISCSI_ENABLED_FOR_MPIO) {
  995. //
  996. // This new Attempt is enabled for MPIO; enable the multipath mode.
  997. //
  998. mPrivate->EnableMpio = TRUE;
  999. mPrivate->MpioCount++;
  1000. } else if (IfrNvData->Enabled == ISCSI_ENABLED) {
  1001. mPrivate->SinglePathCount++;
  1002. }
  1003. IScsiConfigUpdateAttempt ();
  1004. }
  1005. Attempt->SessionConfigData.Enabled = IfrNvData->Enabled;
  1006. //
  1007. // Record the user configuration information in NVR.
  1008. //
  1009. UnicodeSPrint (mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE, L"Attempt %d", Attempt->AttemptConfigIndex);
  1010. FreePool (MacString);
  1011. return gRT->SetVariable (
  1012. mPrivate->PortString,
  1013. &gEfiIScsiInitiatorNameProtocolGuid,
  1014. ISCSI_CONFIG_VAR_ATTR,
  1015. sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA),
  1016. Attempt
  1017. );
  1018. }
  1019. /**
  1020. Convert the IFR data configured by keyword to iSCSI configuration data.
  1021. @param[in] IfrNvData Point to ISCSI_CONFIG_IFR_NVDATA.
  1022. @param[in] OffSet The offset of the variable to the configuration structure.
  1023. @retval EFI_INVALID_PARAMETER Any input or configured parameter is invalid.
  1024. @retval EFI_SUCCESS The operation is completed successfully.
  1025. **/
  1026. EFI_STATUS
  1027. IScsiConvertlfrNvDataToAttemptConfigDataByKeyword (
  1028. IN ISCSI_CONFIG_IFR_NVDATA *IfrNvData,
  1029. IN UINTN OffSet
  1030. )
  1031. {
  1032. ISCSI_ATTEMPT_CONFIG_NVDATA *Attempt;
  1033. UINT8 AttemptIndex;
  1034. UINT8 Index;
  1035. UINT8 ChapSecretLen;
  1036. UINT8 ReverseChapSecretLen;
  1037. CHAR16 *AttemptName1;
  1038. CHAR16 *AttemptName2;
  1039. ISCSI_ATTEMPT_CONFIG_NVDATA *SameNicAttempt;
  1040. CHAR8 LunString[ISCSI_LUN_STR_MAX_LEN];
  1041. CHAR8 IScsiName[ISCSI_NAME_MAX_SIZE];
  1042. CHAR8 IpString[IP_STR_MAX_SIZE];
  1043. EFI_IP_ADDRESS HostIp;
  1044. EFI_IP_ADDRESS SubnetMask;
  1045. EFI_IP_ADDRESS Gateway;
  1046. EFI_INPUT_KEY Key;
  1047. UINT64 Lun;
  1048. EFI_STATUS Status;
  1049. Attempt = NULL;
  1050. ZeroMem (IScsiName, sizeof (IScsiName));
  1051. if (OffSet < ATTEMPT_BOOTENABLE_VAR_OFFSET) {
  1052. return EFI_SUCCESS;
  1053. } else if ((OffSet >= ATTEMPT_BOOTENABLE_VAR_OFFSET) && (OffSet < ATTEMPT_ADDRESS_TYPE_VAR_OFFSET)) {
  1054. AttemptIndex = (UINT8) ((OffSet - ATTEMPT_BOOTENABLE_VAR_OFFSET) + 1);
  1055. Attempt = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
  1056. if (Attempt == NULL) {
  1057. return EFI_INVALID_PARAMETER;
  1058. }
  1059. IfrNvData->Enabled = IfrNvData->ISCSIBootEnableList[AttemptIndex - 1];
  1060. //
  1061. // Validate the configuration of attempt.
  1062. //
  1063. if (IfrNvData->Enabled != ISCSI_DISABLED) {
  1064. //
  1065. // Check whether this attempt uses NIC which is already used by existing attempt.
  1066. //
  1067. SameNicAttempt = IScsiConfigGetAttemptByNic (Attempt, IfrNvData->Enabled);
  1068. if (SameNicAttempt != NULL) {
  1069. AttemptName1 = (CHAR16 *) AllocateZeroPool (ATTEMPT_NAME_SIZE * sizeof (CHAR16));
  1070. if (AttemptName1 == NULL) {
  1071. return EFI_OUT_OF_RESOURCES;
  1072. }
  1073. AttemptName2 = (CHAR16 *) AllocateZeroPool (ATTEMPT_NAME_SIZE * sizeof (CHAR16));
  1074. if (AttemptName2 == NULL) {
  1075. FreePool (AttemptName1);
  1076. return EFI_OUT_OF_RESOURCES;
  1077. }
  1078. AsciiStrToUnicodeStrS (Attempt->AttemptName, AttemptName1, ATTEMPT_NAME_SIZE);
  1079. AsciiStrToUnicodeStrS (SameNicAttempt->AttemptName, AttemptName2, ATTEMPT_NAME_SIZE);
  1080. UnicodeSPrint (
  1081. mPrivate->PortString,
  1082. (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
  1083. L"Warning! \"%s\" uses same NIC as Attempt \"%s\".",
  1084. AttemptName1,
  1085. AttemptName2
  1086. );
  1087. CreatePopUp (
  1088. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1089. &Key,
  1090. mPrivate->PortString,
  1091. NULL
  1092. );
  1093. FreePool (AttemptName1);
  1094. FreePool (AttemptName2);
  1095. }
  1096. }
  1097. if (IfrNvData->Enabled == ISCSI_DISABLED &&
  1098. Attempt->SessionConfigData.Enabled != ISCSI_DISABLED) {
  1099. //
  1100. // User updates the Attempt from "Enabled"/"Enabled for MPIO" to "Disabled".
  1101. //
  1102. if (Attempt->SessionConfigData.Enabled == ISCSI_ENABLED_FOR_MPIO) {
  1103. if (mPrivate->MpioCount < 1) {
  1104. return EFI_ABORTED;
  1105. }
  1106. if (--mPrivate->MpioCount == 0) {
  1107. mPrivate->EnableMpio = FALSE;
  1108. }
  1109. } else if (Attempt->SessionConfigData.Enabled == ISCSI_ENABLED) {
  1110. if (mPrivate->SinglePathCount < 1) {
  1111. return EFI_ABORTED;
  1112. }
  1113. mPrivate->SinglePathCount--;
  1114. }
  1115. } else if (IfrNvData->Enabled == ISCSI_ENABLED_FOR_MPIO &&
  1116. Attempt->SessionConfigData.Enabled == ISCSI_ENABLED) {
  1117. //
  1118. // User updates the Attempt from "Enabled" to "Enabled for MPIO".
  1119. //
  1120. if (mPrivate->SinglePathCount < 1) {
  1121. return EFI_ABORTED;
  1122. }
  1123. mPrivate->EnableMpio = TRUE;
  1124. mPrivate->MpioCount++;
  1125. mPrivate->SinglePathCount--;
  1126. } else if (IfrNvData->Enabled == ISCSI_ENABLED &&
  1127. Attempt->SessionConfigData.Enabled == ISCSI_ENABLED_FOR_MPIO) {
  1128. //
  1129. // User updates the Attempt from "Enabled for MPIO" to "Enabled".
  1130. //
  1131. if (mPrivate->MpioCount < 1) {
  1132. return EFI_ABORTED;
  1133. }
  1134. if (--mPrivate->MpioCount == 0) {
  1135. mPrivate->EnableMpio = FALSE;
  1136. }
  1137. mPrivate->SinglePathCount++;
  1138. } else if (IfrNvData->Enabled != ISCSI_DISABLED &&
  1139. Attempt->SessionConfigData.Enabled == ISCSI_DISABLED) {
  1140. //
  1141. // User updates the Attempt from "Disabled" to "Enabled"/"Enabled for MPIO".
  1142. //
  1143. if (IfrNvData->Enabled == ISCSI_ENABLED_FOR_MPIO) {
  1144. mPrivate->EnableMpio = TRUE;
  1145. mPrivate->MpioCount++;
  1146. } else if (IfrNvData->Enabled == ISCSI_ENABLED) {
  1147. mPrivate->SinglePathCount++;
  1148. }
  1149. }
  1150. Attempt->SessionConfigData.Enabled = IfrNvData->Enabled;
  1151. } else if ((OffSet >= ATTEMPT_ADDRESS_TYPE_VAR_OFFSET) && (OffSet < ATTEMPT_CONNECT_RETRY_VAR_OFFSET)) {
  1152. AttemptIndex = (UINT8) ((OffSet - ATTEMPT_ADDRESS_TYPE_VAR_OFFSET) + 1);
  1153. Attempt = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
  1154. if (Attempt == NULL) {
  1155. return EFI_INVALID_PARAMETER;
  1156. }
  1157. Attempt->SessionConfigData.IpMode = IfrNvData->ISCSIIpAddressTypeList[AttemptIndex - 1];
  1158. if (Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) {
  1159. Attempt->AutoConfigureMode = 0;
  1160. }
  1161. } else if ((OffSet >= ATTEMPT_CONNECT_RETRY_VAR_OFFSET) && (OffSet < ATTEMPT_CONNECT_TIMEOUT_VAR_OFFSET)) {
  1162. AttemptIndex = (UINT8) ((OffSet - ATTEMPT_CONNECT_RETRY_VAR_OFFSET) + 1);
  1163. Attempt = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
  1164. if (Attempt == NULL) {
  1165. return EFI_INVALID_PARAMETER;
  1166. }
  1167. if (IfrNvData->ISCSIConnectRetry[AttemptIndex - 1] > CONNECT_MAX_RETRY) {
  1168. CreatePopUp (
  1169. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1170. &Key,
  1171. L"The minimum value is 0 and the maximum is 16. 0 means no retry.",
  1172. NULL
  1173. );
  1174. return EFI_INVALID_PARAMETER;
  1175. }
  1176. Attempt->SessionConfigData.ConnectRetryCount = IfrNvData->ISCSIConnectRetry[AttemptIndex - 1];
  1177. } else if ((OffSet >= ATTEMPT_CONNECT_TIMEOUT_VAR_OFFSET) && (OffSet < ATTEMPT_INITIATOR_VIA_DHCP_VAR_OFFSET)) {
  1178. AttemptIndex = (UINT8) ((OffSet - ATTEMPT_CONNECT_TIMEOUT_VAR_OFFSET) / 2 + 1);
  1179. Attempt = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
  1180. if (Attempt == NULL) {
  1181. return EFI_INVALID_PARAMETER;
  1182. }
  1183. if ((IfrNvData->ISCSIConnectTimeout[AttemptIndex - 1] < CONNECT_MIN_TIMEOUT) ||
  1184. (IfrNvData->ISCSIConnectTimeout[AttemptIndex - 1] > CONNECT_MAX_TIMEOUT)) {
  1185. CreatePopUp (
  1186. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1187. &Key,
  1188. L"The minimum value is 100 milliseconds and the maximum is 20 seconds.",
  1189. NULL
  1190. );
  1191. return EFI_INVALID_PARAMETER;
  1192. }
  1193. Attempt->SessionConfigData.ConnectTimeout = IfrNvData->ISCSIConnectTimeout[AttemptIndex - 1];
  1194. if (Attempt->SessionConfigData.ConnectTimeout == 0) {
  1195. Attempt->SessionConfigData.ConnectTimeout = CONNECT_DEFAULT_TIMEOUT;
  1196. }
  1197. } else if ((OffSet >= ATTEMPT_INITIATOR_VIA_DHCP_VAR_OFFSET) && (OffSet < ATTEMPT_TARGET_VIA_DHCP_VAR_OFFSET)) {
  1198. AttemptIndex = (UINT8) ((OffSet - ATTEMPT_INITIATOR_VIA_DHCP_VAR_OFFSET) + 1);
  1199. Attempt = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
  1200. if (Attempt == NULL) {
  1201. return EFI_INVALID_PARAMETER;
  1202. }
  1203. Attempt->SessionConfigData.InitiatorInfoFromDhcp = IfrNvData->ISCSIInitiatorInfoViaDHCP[AttemptIndex - 1];
  1204. } else if ((OffSet >= ATTEMPT_TARGET_VIA_DHCP_VAR_OFFSET) && (OffSet < ATTEMPT_TARGET_TCP_PORT_VAR_OFFSET)) {
  1205. AttemptIndex = (UINT8) ((OffSet - ATTEMPT_TARGET_VIA_DHCP_VAR_OFFSET) + 1);
  1206. Attempt = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
  1207. if (Attempt == NULL) {
  1208. return EFI_INVALID_PARAMETER;
  1209. }
  1210. if ((Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) && (Attempt->SessionConfigData.InitiatorInfoFromDhcp)) {
  1211. Attempt->SessionConfigData.TargetInfoFromDhcp = IfrNvData->ISCSITargetInfoViaDHCP[AttemptIndex - 1];
  1212. } else {
  1213. CreatePopUp (
  1214. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1215. &Key,
  1216. L"Invalid Configuration, Check value of IpMode or Enable DHCP!",
  1217. NULL
  1218. );
  1219. return EFI_INVALID_PARAMETER;
  1220. }
  1221. } else if ((OffSet >= ATTEMPT_TARGET_TCP_PORT_VAR_OFFSET) && (OffSet < ATTEMPT_AUTHENTICATION_METHOD_VAR_OFFSET)) {
  1222. AttemptIndex = (UINT8) ((OffSet - ATTEMPT_TARGET_TCP_PORT_VAR_OFFSET) / 2 + 1);
  1223. Attempt = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
  1224. if (Attempt == NULL) {
  1225. return EFI_INVALID_PARAMETER;
  1226. }
  1227. if ((Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) && (!Attempt->SessionConfigData.TargetInfoFromDhcp)) {
  1228. Attempt->SessionConfigData.TargetPort = IfrNvData->ISCSITargetTcpPort[AttemptIndex - 1];
  1229. if (Attempt->SessionConfigData.TargetPort == 0) {
  1230. Attempt->SessionConfigData.TargetPort = ISCSI_WELL_KNOWN_PORT;
  1231. }
  1232. } else {
  1233. CreatePopUp (
  1234. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1235. &Key,
  1236. L"Invalid Configuration, Check value of IpMode or Target Via DHCP!",
  1237. NULL
  1238. );
  1239. return EFI_INVALID_PARAMETER;
  1240. }
  1241. } else if ((OffSet >= ATTEMPT_AUTHENTICATION_METHOD_VAR_OFFSET) && (OffSet < ATTEMPT_CHARTYPE_VAR_OFFSET)) {
  1242. AttemptIndex = (UINT8) ((OffSet - ATTEMPT_AUTHENTICATION_METHOD_VAR_OFFSET) + 1);
  1243. Attempt = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
  1244. if (Attempt == NULL) {
  1245. return EFI_INVALID_PARAMETER;
  1246. }
  1247. Attempt->AuthenticationType = IfrNvData->ISCSIAuthenticationMethod[AttemptIndex - 1];
  1248. } else if ((OffSet >= ATTEMPT_CHARTYPE_VAR_OFFSET) && (OffSet < ATTEMPT_ISID_VAR_OFFSET)) {
  1249. AttemptIndex = (UINT8) ((OffSet - ATTEMPT_CHARTYPE_VAR_OFFSET) + 1);
  1250. Attempt = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
  1251. if (Attempt == NULL) {
  1252. return EFI_INVALID_PARAMETER;
  1253. }
  1254. if (Attempt->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {
  1255. Attempt->AuthConfigData.CHAP.CHAPType = IfrNvData->ISCSIChapType[AttemptIndex - 1];
  1256. }
  1257. } else if (OffSet >= ATTEMPT_ISID_VAR_OFFSET) {
  1258. Index = (UINT8) ((OffSet - ATTEMPT_ISID_VAR_OFFSET) / sizeof (KEYWORD_STR));
  1259. AttemptIndex = Index + 1;
  1260. Attempt = IScsiConfigGetAttemptByConfigIndex (AttemptIndex);
  1261. if (Attempt == NULL) {
  1262. return EFI_INVALID_PARAMETER;
  1263. }
  1264. OffSet = OffSet - Index * sizeof (KEYWORD_STR);
  1265. if ((OffSet >= ATTEMPT_ISID_VAR_OFFSET) && (OffSet < ATTEMPT_INITIATOR_IP_ADDRESS_VAR_OFFSET)) {
  1266. IScsiParseIsIdFromString (IfrNvData->Keyword[Index].ISCSIIsId, Attempt->SessionConfigData.IsId);
  1267. } else if ((OffSet >= ATTEMPT_INITIATOR_IP_ADDRESS_VAR_OFFSET) && (OffSet < ATTEMPT_INITIATOR_NET_MASK_VAR_OFFSET)) {
  1268. if ((Attempt->SessionConfigData.IpMode == IP_MODE_IP4) && (!Attempt->SessionConfigData.InitiatorInfoFromDhcp)) {
  1269. //
  1270. // Config Local ip
  1271. //
  1272. Status = NetLibStrToIp4 (IfrNvData->Keyword[Index].ISCSIInitiatorIpAddress, &HostIp.v4);
  1273. if (EFI_ERROR (Status) || ((Attempt->SessionConfigData.SubnetMask.Addr[0] != 0) &&
  1274. !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), NTOHL(*(UINT32*)Attempt->SessionConfigData.SubnetMask.Addr)))) {
  1275. CreatePopUp (
  1276. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1277. &Key,
  1278. L"Invalid IP address!",
  1279. NULL
  1280. );
  1281. return EFI_INVALID_PARAMETER;
  1282. } else {
  1283. CopyMem (&Attempt->SessionConfigData.LocalIp, &HostIp.v4, sizeof (HostIp.v4));
  1284. }
  1285. } else {
  1286. CreatePopUp (
  1287. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1288. &Key,
  1289. L"Invalid Configuration, Check value of IpMode or Enable DHCP!",
  1290. NULL
  1291. );
  1292. return EFI_INVALID_PARAMETER;
  1293. }
  1294. } else if ((OffSet >= ATTEMPT_INITIATOR_NET_MASK_VAR_OFFSET) && (OffSet < ATTEMPT_INITIATOR_GATE_WAY_VAR_OFFSET)) {
  1295. if ((Attempt->SessionConfigData.IpMode == IP_MODE_IP4) && (!Attempt->SessionConfigData.InitiatorInfoFromDhcp)) {
  1296. Status = NetLibStrToIp4 (IfrNvData->Keyword[Index].ISCSIInitiatorNetmask, &SubnetMask.v4);
  1297. if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] != 0) && (IScsiGetSubnetMaskPrefixLength (&SubnetMask.v4) == 0))) {
  1298. CreatePopUp (
  1299. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1300. &Key,
  1301. L"Invalid Subnet Mask!",
  1302. NULL
  1303. );
  1304. return EFI_INVALID_PARAMETER;
  1305. } else {
  1306. CopyMem (&Attempt->SessionConfigData.SubnetMask, &SubnetMask.v4, sizeof (SubnetMask.v4));
  1307. }
  1308. } else {
  1309. CreatePopUp (
  1310. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1311. &Key,
  1312. L"Invalid Configuration, Check value of IpMode or Enable DHCP!",
  1313. NULL
  1314. );
  1315. return EFI_INVALID_PARAMETER;
  1316. }
  1317. } else if ((OffSet >= ATTEMPT_INITIATOR_GATE_WAY_VAR_OFFSET) && (OffSet < ATTEMPT_TARGET_NAME_VAR_OFFSET)) {
  1318. if ((Attempt->SessionConfigData.IpMode == IP_MODE_IP4) && (!Attempt->SessionConfigData.InitiatorInfoFromDhcp)) {
  1319. Status = NetLibStrToIp4 (IfrNvData->Keyword[Index].ISCSIInitiatorGateway, &Gateway.v4);
  1320. if (EFI_ERROR (Status) ||
  1321. ((Gateway.Addr[0] != 0) && (Attempt->SessionConfigData.SubnetMask.Addr[0] != 0) &&
  1322. !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), NTOHL(*(UINT32*)Attempt->SessionConfigData.SubnetMask.Addr)))) {
  1323. CreatePopUp (
  1324. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1325. &Key,
  1326. L"Invalid Gateway!",
  1327. NULL
  1328. );
  1329. return EFI_INVALID_PARAMETER;
  1330. } else {
  1331. CopyMem (&Attempt->SessionConfigData.Gateway, &Gateway.v4, sizeof (Gateway.v4));
  1332. }
  1333. } else {
  1334. CreatePopUp (
  1335. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1336. &Key,
  1337. L"Invalid Configuration, Check value of IpMode or Enable DHCP!",
  1338. NULL
  1339. );
  1340. return EFI_INVALID_PARAMETER;
  1341. }
  1342. } else if ((OffSet >= ATTEMPT_TARGET_NAME_VAR_OFFSET) && (OffSet < ATTEMPT_TARGET_IP_ADDRESS_VAR_OFFSET)) {
  1343. if ((Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) && (!Attempt->SessionConfigData.TargetInfoFromDhcp)) {
  1344. UnicodeStrToAsciiStrS (IfrNvData->Keyword[Index].ISCSITargetName, IScsiName, ISCSI_NAME_MAX_SIZE);
  1345. Status = IScsiNormalizeName (IScsiName, AsciiStrLen (IScsiName));
  1346. if (EFI_ERROR (Status)) {
  1347. CreatePopUp (
  1348. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1349. &Key,
  1350. L"Invalid iSCSI Name!",
  1351. NULL
  1352. );
  1353. } else {
  1354. AsciiStrCpyS (Attempt->SessionConfigData.TargetName, ISCSI_NAME_MAX_SIZE, IScsiName);
  1355. }
  1356. if (Attempt->SessionConfigData.Enabled != ISCSI_DISABLED) {
  1357. if (Attempt->SessionConfigData.TargetName[0] == L'\0') {
  1358. CreatePopUp (
  1359. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1360. &Key,
  1361. L"iSCSI target name is NULL!",
  1362. NULL
  1363. );
  1364. return EFI_INVALID_PARAMETER;
  1365. }
  1366. }
  1367. } else {
  1368. CreatePopUp (
  1369. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1370. &Key,
  1371. L"Invalid Configuration, Check value of IpMode or Target Via DHCP!",
  1372. NULL
  1373. );
  1374. return EFI_INVALID_PARAMETER;
  1375. }
  1376. } else if ((OffSet >= ATTEMPT_TARGET_IP_ADDRESS_VAR_OFFSET) && (OffSet < ATTEMPT_LUN_VAR_OFFSET)) {
  1377. if ((Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) && (!Attempt->SessionConfigData.TargetInfoFromDhcp)) {
  1378. UnicodeStrToAsciiStrS (IfrNvData->Keyword[Index].ISCSITargetIpAddress, IpString, sizeof (IpString));
  1379. Status = IScsiAsciiStrToIp (IpString, Attempt->SessionConfigData.IpMode, &HostIp);
  1380. if (EFI_ERROR (Status) || !IpIsUnicast (&HostIp, Attempt->SessionConfigData.IpMode)) {
  1381. Attempt->SessionConfigData.DnsMode = TRUE;
  1382. ZeroMem (&Attempt->SessionConfigData.TargetIp, sizeof (Attempt->SessionConfigData.TargetIp));
  1383. UnicodeStrToAsciiStrS (IfrNvData->Keyword[Index].ISCSITargetIpAddress, Attempt->SessionConfigData.TargetUrl, ISCSI_NAME_MAX_SIZE);
  1384. } else {
  1385. Attempt->SessionConfigData.DnsMode = FALSE;
  1386. CopyMem (&Attempt->SessionConfigData.TargetIp, &HostIp, sizeof (HostIp));
  1387. }
  1388. } else {
  1389. CreatePopUp (
  1390. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1391. &Key,
  1392. L"Invalid Configuration, Check value of IpMode or Target Via DHCP!",
  1393. NULL
  1394. );
  1395. return EFI_INVALID_PARAMETER;
  1396. }
  1397. } else if ((OffSet >= ATTEMPT_LUN_VAR_OFFSET) && (OffSet < ATTEMPT_CHAR_USER_NAME_VAR_OFFSET)) {
  1398. if ((Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) && (Attempt->SessionConfigData.TargetInfoFromDhcp == 0)) {
  1399. //
  1400. // Config LUN.
  1401. //
  1402. UnicodeStrToAsciiStrS (IfrNvData->Keyword[Index].ISCSILun, LunString, ISCSI_LUN_STR_MAX_LEN);
  1403. Status = IScsiAsciiStrToLun (LunString, (UINT8 *) &Lun);
  1404. if (EFI_ERROR (Status)) {
  1405. CreatePopUp (
  1406. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1407. &Key,
  1408. L"Invalid LUN string, Examples are: 4752-3A4F-6b7e-2F99, 6734-9-156f-127, 4186-9!",
  1409. NULL
  1410. );
  1411. } else {
  1412. CopyMem (&Attempt->SessionConfigData.BootLun, &Lun, sizeof (Lun));
  1413. }
  1414. } else {
  1415. CreatePopUp (
  1416. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1417. &Key,
  1418. L"Invalid Configuration, Check value of IpMode or Target Via DHCP!",
  1419. NULL
  1420. );
  1421. return EFI_INVALID_PARAMETER;
  1422. }
  1423. } else if ((OffSet >= ATTEMPT_CHAR_USER_NAME_VAR_OFFSET) && (OffSet < ATTEMPT_CHAR_SECRET_VAR_OFFSET)) {
  1424. if (Attempt->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {
  1425. UnicodeStrToAsciiStrS (
  1426. IfrNvData->Keyword[Index].ISCSIChapUsername,
  1427. Attempt->AuthConfigData.CHAP.CHAPName,
  1428. ISCSI_CHAP_NAME_STORAGE
  1429. );
  1430. if (Attempt->SessionConfigData.Enabled != ISCSI_DISABLED) {
  1431. if (IfrNvData->Keyword[Index].ISCSIChapUsername[0] == L'\0') {
  1432. CreatePopUp (
  1433. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1434. &Key,
  1435. L"CHAP Name is invalid!",
  1436. NULL
  1437. );
  1438. return EFI_INVALID_PARAMETER;
  1439. }
  1440. }
  1441. } else {
  1442. CreatePopUp (
  1443. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1444. &Key,
  1445. L"Invalid Configuration, Check value of AuthenticationType!",
  1446. NULL
  1447. );
  1448. return EFI_INVALID_PARAMETER;
  1449. }
  1450. } else if ((OffSet >= ATTEMPT_CHAR_SECRET_VAR_OFFSET) && (OffSet < ATTEMPT_CHAR_REVERSE_USER_NAME_VAR_OFFSET)) {
  1451. if (Attempt->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {
  1452. ChapSecretLen = (UINT8)StrLen (IfrNvData->Keyword[Index].ISCSIChapSecret);
  1453. UnicodeStrToAsciiStrS (
  1454. IfrNvData->Keyword[Index].ISCSIChapSecret,
  1455. Attempt->AuthConfigData.CHAP.CHAPSecret,
  1456. ISCSI_CHAP_SECRET_STORAGE
  1457. );
  1458. if (Attempt->SessionConfigData.Enabled != ISCSI_DISABLED) {
  1459. if ((ChapSecretLen < ISCSI_CHAP_SECRET_MIN_LEN) || (ChapSecretLen > ISCSI_CHAP_SECRET_MAX_LEN)) {
  1460. CreatePopUp (
  1461. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1462. &Key,
  1463. L"The Chap Secret minimum length is 12 bytes and the maximum length is 16 bytes.",
  1464. NULL
  1465. );
  1466. return EFI_INVALID_PARAMETER;
  1467. }
  1468. }
  1469. } else {
  1470. CreatePopUp (
  1471. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1472. &Key,
  1473. L"Invalid Configuration, Check value of AuthenticationType!",
  1474. NULL
  1475. );
  1476. return EFI_INVALID_PARAMETER;
  1477. }
  1478. } else if ((OffSet >= ATTEMPT_CHAR_REVERSE_USER_NAME_VAR_OFFSET) && (OffSet < ATTEMPT_CHAR_REVERSE_SECRET_VAR_OFFSET)) {
  1479. if (Attempt->AuthConfigData.CHAP.CHAPType == ISCSI_CHAP_MUTUAL) {
  1480. UnicodeStrToAsciiStrS (
  1481. IfrNvData->Keyword[Index].ISCSIReverseChapUsername,
  1482. Attempt->AuthConfigData.CHAP.ReverseCHAPName,
  1483. ISCSI_CHAP_NAME_STORAGE
  1484. );
  1485. if (Attempt->SessionConfigData.Enabled != ISCSI_DISABLED) {
  1486. if (IfrNvData->Keyword[Index].ISCSIReverseChapUsername[0] == L'\0') {
  1487. CreatePopUp (
  1488. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1489. &Key,
  1490. L"Reverse CHAP Name is invalid!",
  1491. NULL
  1492. );
  1493. return EFI_INVALID_PARAMETER;
  1494. }
  1495. }
  1496. } else {
  1497. CreatePopUp (
  1498. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1499. &Key,
  1500. L"Invalid Configuration, Check value of AuthenticationType or Chap Type!",
  1501. NULL
  1502. );
  1503. return EFI_INVALID_PARAMETER;
  1504. }
  1505. } else if (OffSet >= ATTEMPT_CHAR_REVERSE_SECRET_VAR_OFFSET) {
  1506. if (Attempt->AuthConfigData.CHAP.CHAPType == ISCSI_CHAP_MUTUAL) {
  1507. ReverseChapSecretLen = (UINT8)StrLen (IfrNvData->Keyword[Index].ISCSIReverseChapSecret);
  1508. UnicodeStrToAsciiStrS (
  1509. IfrNvData->Keyword[Index].ISCSIReverseChapSecret,
  1510. Attempt->AuthConfigData.CHAP.ReverseCHAPSecret,
  1511. ISCSI_CHAP_SECRET_STORAGE
  1512. );
  1513. if (Attempt->SessionConfigData.Enabled != ISCSI_DISABLED) {
  1514. if ((ReverseChapSecretLen < ISCSI_CHAP_SECRET_MIN_LEN) || (ReverseChapSecretLen > ISCSI_CHAP_SECRET_MAX_LEN)) {
  1515. CreatePopUp (
  1516. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1517. &Key,
  1518. L"The Reverse CHAP Secret minimum length is 12 bytes and the maximum length is 16 bytes.",
  1519. NULL
  1520. );
  1521. return EFI_INVALID_PARAMETER;
  1522. }
  1523. }
  1524. } else {
  1525. CreatePopUp (
  1526. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1527. &Key,
  1528. L"Invalid Configuration, Check value of AuthenticationType or Chap Type!",
  1529. NULL
  1530. );
  1531. return EFI_INVALID_PARAMETER;
  1532. }
  1533. }
  1534. }
  1535. //
  1536. // Record the user configuration information in NVR.
  1537. //
  1538. ASSERT (Attempt != NULL);
  1539. UnicodeSPrint (mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE, L"Attempt %d", Attempt->AttemptConfigIndex);
  1540. return gRT->SetVariable (
  1541. mPrivate->PortString,
  1542. &gEfiIScsiInitiatorNameProtocolGuid,
  1543. ISCSI_CONFIG_VAR_ATTR,
  1544. sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA),
  1545. Attempt
  1546. );
  1547. }
  1548. /**
  1549. Create Hii Extend Label OpCode as the start opcode and end opcode. It is
  1550. a help function.
  1551. @param[in] StartLabelNumber The number of start label.
  1552. @param[out] StartOpCodeHandle Points to the start opcode handle.
  1553. @param[out] StartLabel Points to the created start opcode.
  1554. @param[out] EndOpCodeHandle Points to the end opcode handle.
  1555. @param[out] EndLabel Points to the created end opcode.
  1556. @retval EFI_OUT_OF_RESOURCES Do not have sufficient resource to finish this
  1557. operation.
  1558. @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
  1559. @retval EFI_SUCCESS The operation is completed successfully.
  1560. **/
  1561. EFI_STATUS
  1562. IScsiCreateOpCode (
  1563. IN UINT16 StartLabelNumber,
  1564. OUT VOID **StartOpCodeHandle,
  1565. OUT EFI_IFR_GUID_LABEL **StartLabel,
  1566. OUT VOID **EndOpCodeHandle,
  1567. OUT EFI_IFR_GUID_LABEL **EndLabel
  1568. )
  1569. {
  1570. EFI_STATUS Status;
  1571. EFI_IFR_GUID_LABEL *InternalStartLabel;
  1572. EFI_IFR_GUID_LABEL *InternalEndLabel;
  1573. if (StartOpCodeHandle == NULL || StartLabel == NULL || EndOpCodeHandle == NULL || EndLabel == NULL) {
  1574. return EFI_INVALID_PARAMETER;
  1575. }
  1576. *StartOpCodeHandle = NULL;
  1577. *EndOpCodeHandle = NULL;
  1578. Status = EFI_OUT_OF_RESOURCES;
  1579. //
  1580. // Initialize the container for dynamic opcodes.
  1581. //
  1582. *StartOpCodeHandle = HiiAllocateOpCodeHandle ();
  1583. if (*StartOpCodeHandle == NULL) {
  1584. return Status;
  1585. }
  1586. *EndOpCodeHandle = HiiAllocateOpCodeHandle ();
  1587. if (*EndOpCodeHandle == NULL) {
  1588. goto Exit;
  1589. }
  1590. //
  1591. // Create Hii Extend Label OpCode as the start opcode.
  1592. //
  1593. InternalStartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (
  1594. *StartOpCodeHandle,
  1595. &gEfiIfrTianoGuid,
  1596. NULL,
  1597. sizeof (EFI_IFR_GUID_LABEL)
  1598. );
  1599. if (InternalStartLabel == NULL) {
  1600. goto Exit;
  1601. }
  1602. InternalStartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
  1603. InternalStartLabel->Number = StartLabelNumber;
  1604. //
  1605. // Create Hii Extend Label OpCode as the end opcode.
  1606. //
  1607. InternalEndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (
  1608. *EndOpCodeHandle,
  1609. &gEfiIfrTianoGuid,
  1610. NULL,
  1611. sizeof (EFI_IFR_GUID_LABEL)
  1612. );
  1613. if (InternalEndLabel == NULL) {
  1614. goto Exit;
  1615. }
  1616. InternalEndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
  1617. InternalEndLabel->Number = LABEL_END;
  1618. *StartLabel = InternalStartLabel;
  1619. *EndLabel = InternalEndLabel;
  1620. return EFI_SUCCESS;
  1621. Exit:
  1622. if (*StartOpCodeHandle != NULL) {
  1623. HiiFreeOpCodeHandle (*StartOpCodeHandle);
  1624. }
  1625. if (*EndOpCodeHandle != NULL) {
  1626. HiiFreeOpCodeHandle (*EndOpCodeHandle);
  1627. }
  1628. return Status;
  1629. }
  1630. /**
  1631. Update the MAIN form to display the configured attempts.
  1632. **/
  1633. VOID
  1634. IScsiConfigUpdateAttempt (
  1635. VOID
  1636. )
  1637. {
  1638. LIST_ENTRY *Entry;
  1639. ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;
  1640. VOID *StartOpCodeHandle;
  1641. EFI_IFR_GUID_LABEL *StartLabel;
  1642. VOID *EndOpCodeHandle;
  1643. EFI_IFR_GUID_LABEL *EndLabel;
  1644. EFI_STATUS Status;
  1645. Status = IScsiCreateOpCode (
  1646. ATTEMPT_ENTRY_LABEL,
  1647. &StartOpCodeHandle,
  1648. &StartLabel,
  1649. &EndOpCodeHandle,
  1650. &EndLabel
  1651. );
  1652. if (EFI_ERROR (Status)) {
  1653. return ;
  1654. }
  1655. NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {
  1656. AttemptConfigData = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
  1657. if (AttemptConfigData->Actived == ISCSI_ACTIVE_ENABLED) {
  1658. //
  1659. // Update Attempt Help Info.
  1660. //
  1661. UnicodeSPrint (mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE, L"Attempt %d", (UINTN) AttemptConfigData->AttemptConfigIndex);
  1662. AttemptConfigData->AttemptTitleToken = HiiSetString (
  1663. mCallbackInfo->RegisteredHandle,
  1664. 0,
  1665. mPrivate->PortString,
  1666. NULL
  1667. );
  1668. if (AttemptConfigData->AttemptTitleToken == 0) {
  1669. return ;
  1670. }
  1671. HiiCreateGotoOpCode (
  1672. StartOpCodeHandle, // Container for dynamic created opcodes
  1673. FORMID_ATTEMPT_FORM, // Form ID
  1674. AttemptConfigData->AttemptTitleToken, // Prompt text
  1675. AttemptConfigData->AttemptTitleHelpToken, // Help text
  1676. EFI_IFR_FLAG_CALLBACK, // Question flag
  1677. (UINT16) (KEY_ATTEMPT_ENTRY_BASE + AttemptConfigData->AttemptConfigIndex) // Question ID
  1678. );
  1679. }
  1680. }
  1681. HiiUpdateForm (
  1682. mCallbackInfo->RegisteredHandle, // HII handle
  1683. &gIScsiConfigGuid, // Formset GUID
  1684. FORMID_MAIN_FORM, // Form ID
  1685. StartOpCodeHandle, // Label for where to insert opcodes
  1686. EndOpCodeHandle // Replace data
  1687. );
  1688. HiiFreeOpCodeHandle (StartOpCodeHandle);
  1689. HiiFreeOpCodeHandle (EndOpCodeHandle);
  1690. }
  1691. /**
  1692. Callback function when user presses "Add an Attempt".
  1693. @retval EFI_OUT_OF_RESOURCES Does not have sufficient resources to finish this
  1694. operation.
  1695. @retval EFI_SUCCESS The operation is completed successfully.
  1696. **/
  1697. EFI_STATUS
  1698. IScsiConfigAddAttempt (
  1699. VOID
  1700. )
  1701. {
  1702. LIST_ENTRY *Entry;
  1703. ISCSI_NIC_INFO *NicInfo;
  1704. EFI_STRING_ID PortTitleToken;
  1705. EFI_STRING_ID PortTitleHelpToken;
  1706. CHAR16 MacString[ISCSI_MAX_MAC_STRING_LEN];
  1707. EFI_STATUS Status;
  1708. VOID *StartOpCodeHandle;
  1709. EFI_IFR_GUID_LABEL *StartLabel;
  1710. VOID *EndOpCodeHandle;
  1711. EFI_IFR_GUID_LABEL *EndLabel;
  1712. Status = IScsiCreateOpCode (
  1713. MAC_ENTRY_LABEL,
  1714. &StartOpCodeHandle,
  1715. &StartLabel,
  1716. &EndOpCodeHandle,
  1717. &EndLabel
  1718. );
  1719. if (EFI_ERROR (Status)) {
  1720. return Status;
  1721. }
  1722. //
  1723. // Ask user to select a MAC for this attempt.
  1724. //
  1725. NET_LIST_FOR_EACH (Entry, &mPrivate->NicInfoList) {
  1726. NicInfo = NET_LIST_USER_STRUCT (Entry, ISCSI_NIC_INFO, Link);
  1727. IScsiMacAddrToStr (
  1728. &NicInfo->PermanentAddress,
  1729. NicInfo->HwAddressSize,
  1730. NicInfo->VlanId,
  1731. MacString
  1732. );
  1733. UnicodeSPrint (mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE, L"MAC %s", MacString);
  1734. PortTitleToken = HiiSetString (
  1735. mCallbackInfo->RegisteredHandle,
  1736. 0,
  1737. mPrivate->PortString,
  1738. NULL
  1739. );
  1740. if (PortTitleToken == 0) {
  1741. Status = EFI_INVALID_PARAMETER;
  1742. goto Exit;
  1743. }
  1744. UnicodeSPrint (
  1745. mPrivate->PortString,
  1746. (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
  1747. L"PFA: Bus %d | Dev %d | Func %d",
  1748. NicInfo->BusNumber,
  1749. NicInfo->DeviceNumber,
  1750. NicInfo->FunctionNumber
  1751. );
  1752. PortTitleHelpToken = HiiSetString (mCallbackInfo->RegisteredHandle, 0, mPrivate->PortString, NULL);
  1753. if (PortTitleHelpToken == 0) {
  1754. Status = EFI_INVALID_PARAMETER;
  1755. goto Exit;
  1756. }
  1757. HiiCreateGotoOpCode (
  1758. StartOpCodeHandle, // Container for dynamic created opcodes
  1759. FORMID_ATTEMPT_FORM,
  1760. PortTitleToken,
  1761. PortTitleHelpToken,
  1762. EFI_IFR_FLAG_CALLBACK, // Question flag
  1763. (UINT16) (KEY_MAC_ENTRY_BASE + NicInfo->NicIndex)
  1764. );
  1765. }
  1766. Status = HiiUpdateForm (
  1767. mCallbackInfo->RegisteredHandle, // HII handle
  1768. &gIScsiConfigGuid, // Formset GUID
  1769. FORMID_MAC_FORM, // Form ID
  1770. StartOpCodeHandle, // Label for where to insert opcodes
  1771. EndOpCodeHandle // Replace data
  1772. );
  1773. Exit:
  1774. HiiFreeOpCodeHandle (StartOpCodeHandle);
  1775. HiiFreeOpCodeHandle (EndOpCodeHandle);
  1776. return Status;
  1777. }
  1778. /**
  1779. Add the attempts by keyword 'iSCSIAddAttempts', you can use this keyword with
  1780. value 'attempt:1 attempt:2' etc to add one or more attempts once. This is different
  1781. with IScsiConfigAddAttempt function which is used to add attempt by UI configuration.
  1782. @param[in] AttemptList The new attempt List will be added.
  1783. @retval EFI_SUCCESS The operation to add attempt list successfully.
  1784. @retval EFI_INVALID_PARAMETER Any parameter is invalid.
  1785. @retval EFI_NOT_FOUND Cannot find the corresponding variable.
  1786. @retval EFI_OUT_OF_RESOURCES Fail to finish the operation due to lack of
  1787. resources.
  1788. **/
  1789. EFI_STATUS
  1790. IScsiConfigAddAttemptsByKeywords (
  1791. IN UINT8 *AttemptList
  1792. )
  1793. {
  1794. UINT8 Index;
  1795. UINT8 Number;
  1796. UINTN TotalNumber;
  1797. UINT8 Nic;
  1798. UINT8 *AttemptConfigOrder;
  1799. UINTN AttemptConfigOrderSize;
  1800. UINT8 *AttemptConfigOrderTmp;
  1801. ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;
  1802. ISCSI_NIC_INFO *NicInfo;
  1803. CHAR16 MacString[ISCSI_MAX_MAC_STRING_LEN];
  1804. CHAR16 IScsiMode[64];
  1805. CHAR16 IpMode[64];
  1806. EFI_STATUS Status;
  1807. Nic = mPrivate->CurrentNic;
  1808. NicInfo = IScsiGetNicInfoByIndex (Nic);
  1809. if (NicInfo == NULL) {
  1810. return EFI_NOT_FOUND;
  1811. }
  1812. //
  1813. // The MAC info will be recorded in Config Data.
  1814. //
  1815. IScsiMacAddrToStr (
  1816. &NicInfo->PermanentAddress,
  1817. NicInfo->HwAddressSize,
  1818. NicInfo->VlanId,
  1819. MacString
  1820. );
  1821. for (Index = 0; Index < PcdGet8 (PcdMaxIScsiAttemptNumber); Index++) {
  1822. if (AttemptList[Index] == 0) {
  1823. continue;
  1824. }
  1825. //
  1826. // Add the attempt.
  1827. //
  1828. Number = AttemptList[Index];
  1829. UnicodeSPrint (
  1830. mPrivate->PortString,
  1831. (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
  1832. L"Attempt %d",
  1833. Number
  1834. );
  1835. GetVariable2 (
  1836. mPrivate->PortString,
  1837. &gEfiIScsiInitiatorNameProtocolGuid,
  1838. (VOID**)&AttemptConfigData,
  1839. NULL
  1840. );
  1841. if (AttemptConfigData == NULL || AttemptConfigData->Actived == ISCSI_ACTIVE_ENABLED) {
  1842. return EFI_INVALID_PARAMETER;
  1843. }
  1844. AttemptConfigData->Actived = ISCSI_ACTIVE_ENABLED;
  1845. AttemptConfigData->NicIndex = NicInfo->NicIndex;
  1846. UnicodeStrToAsciiStrS (MacString, AttemptConfigData->MacString, ISCSI_MAX_MAC_STRING_LEN);
  1847. //
  1848. // Generate OUI-format ISID based on MAC address.
  1849. //
  1850. CopyMem (AttemptConfigData->SessionConfigData.IsId, &NicInfo->PermanentAddress, 6);
  1851. AttemptConfigData->SessionConfigData.IsId[0] =
  1852. (UINT8) (AttemptConfigData->SessionConfigData.IsId[0] & 0x3F);
  1853. //
  1854. // Configure the iSCSI Mode and IpMode to default.
  1855. // Add Attempt Help Info.
  1856. //
  1857. UnicodeSPrint (IScsiMode, 64, L"Disabled");
  1858. UnicodeSPrint (IpMode, 64, L"IP4");
  1859. UnicodeSPrint (
  1860. mPrivate->PortString,
  1861. (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
  1862. L"MAC: %s, PFA: Bus %d | Dev %d | Func %d, iSCSI mode: %s, IP version: %s",
  1863. MacString,
  1864. NicInfo->BusNumber,
  1865. NicInfo->DeviceNumber,
  1866. NicInfo->FunctionNumber,
  1867. IScsiMode,
  1868. IpMode
  1869. );
  1870. AttemptConfigData->AttemptTitleHelpToken = HiiSetString (
  1871. mCallbackInfo->RegisteredHandle,
  1872. 0,
  1873. mPrivate->PortString,
  1874. NULL
  1875. );
  1876. if (AttemptConfigData->AttemptTitleHelpToken == 0) {
  1877. return EFI_OUT_OF_RESOURCES;
  1878. }
  1879. //
  1880. // Get current Attempt order and number.
  1881. //
  1882. AttemptConfigOrder = IScsiGetVariableAndSize (
  1883. L"AttemptOrder",
  1884. &gIScsiConfigGuid,
  1885. &AttemptConfigOrderSize
  1886. );
  1887. TotalNumber = AttemptConfigOrderSize / sizeof (UINT8);
  1888. TotalNumber++;
  1889. //
  1890. // Append the new created attempt order to the end.
  1891. //
  1892. AttemptConfigOrderTmp = AllocateZeroPool (TotalNumber * sizeof (UINT8));
  1893. if (AttemptConfigOrderTmp == NULL) {
  1894. if (AttemptConfigOrder != NULL) {
  1895. FreePool (AttemptConfigOrder);
  1896. }
  1897. return EFI_OUT_OF_RESOURCES;
  1898. }
  1899. if (AttemptConfigOrder != NULL) {
  1900. CopyMem (AttemptConfigOrderTmp, AttemptConfigOrder, AttemptConfigOrderSize);
  1901. FreePool (AttemptConfigOrder);
  1902. }
  1903. AttemptConfigOrderTmp[TotalNumber - 1] = Number;
  1904. AttemptConfigOrder = AttemptConfigOrderTmp;
  1905. AttemptConfigOrderSize = TotalNumber * sizeof (UINT8);
  1906. Status = gRT->SetVariable (
  1907. L"AttemptOrder",
  1908. &gIScsiConfigGuid,
  1909. EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
  1910. AttemptConfigOrderSize,
  1911. AttemptConfigOrder
  1912. );
  1913. FreePool (AttemptConfigOrder);
  1914. if (EFI_ERROR (Status)) {
  1915. return Status;
  1916. }
  1917. //
  1918. // Record the attempt in global link list.
  1919. //
  1920. InsertTailList (&mPrivate->AttemptConfigs, &AttemptConfigData->Link);
  1921. mPrivate->AttemptCount++;
  1922. UnicodeSPrint (mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE, L"Attempt %d", AttemptConfigData->AttemptConfigIndex);
  1923. gRT->SetVariable (
  1924. mPrivate->PortString,
  1925. &gEfiIScsiInitiatorNameProtocolGuid,
  1926. ISCSI_CONFIG_VAR_ATTR,
  1927. sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA),
  1928. AttemptConfigData
  1929. );
  1930. }
  1931. return EFI_SUCCESS;
  1932. }
  1933. /**
  1934. Callback function when user presses "Commit Changes and Exit" in Delete Attempts or Delete Attempts by Keyword.
  1935. @param[in] IfrNvData The IFR NV data.
  1936. @retval EFI_NOT_FOUND Cannot find the corresponding variable.
  1937. @retval EFI_SUCCESS The operation is completed successfully.
  1938. @retval EFI_ABOTRED This operation is aborted cause of error
  1939. configuration.
  1940. @retval EFI_OUT_OF_RESOURCES Fail to finish the operation due to lack of
  1941. resources.
  1942. **/
  1943. EFI_STATUS
  1944. IScsiConfigDeleteAttempts (
  1945. IN ISCSI_CONFIG_IFR_NVDATA *IfrNvData
  1946. )
  1947. {
  1948. EFI_STATUS Status;
  1949. UINTN Index;
  1950. UINTN NewIndex;
  1951. ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;
  1952. UINT8 *AttemptConfigOrder;
  1953. UINTN AttemptConfigOrderSize;
  1954. UINT8 *AttemptNewOrder;
  1955. UINT8 AttemptConfigIndex;
  1956. UINT32 Attribute;
  1957. UINTN Total;
  1958. UINTN NewTotal;
  1959. LIST_ENTRY *Entry;
  1960. LIST_ENTRY *NextEntry;
  1961. ISCSI_SESSION_CONFIG_NVDATA *ConfigData;
  1962. Index = 0;
  1963. AttemptConfigOrder = IScsiGetVariableAndSize (
  1964. L"AttemptOrder",
  1965. &gIScsiConfigGuid,
  1966. &AttemptConfigOrderSize
  1967. );
  1968. if ((AttemptConfigOrder == NULL) || (AttemptConfigOrderSize == 0)) {
  1969. return EFI_NOT_FOUND;
  1970. }
  1971. AttemptNewOrder = AllocateZeroPool (AttemptConfigOrderSize);
  1972. if (AttemptNewOrder == NULL) {
  1973. Status = EFI_OUT_OF_RESOURCES;
  1974. goto Error;
  1975. }
  1976. Total = AttemptConfigOrderSize / sizeof (UINT8);
  1977. NewTotal = Total;
  1978. NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &mPrivate->AttemptConfigs) {
  1979. if (IfrNvData->DeleteAttemptList[Index] == 0) {
  1980. Index++;
  1981. continue;
  1982. }
  1983. //
  1984. // Delete the attempt.
  1985. //
  1986. AttemptConfigData = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
  1987. //
  1988. // Remove this attempt from UI configured attempt list.
  1989. //
  1990. RemoveEntryList (&AttemptConfigData->Link);
  1991. mPrivate->AttemptCount--;
  1992. if (AttemptConfigData->SessionConfigData.Enabled == ISCSI_ENABLED_FOR_MPIO) {
  1993. if (mPrivate->MpioCount < 1) {
  1994. Status = EFI_ABORTED;
  1995. goto Error;
  1996. }
  1997. //
  1998. // No more attempt is enabled for MPIO. Transit the iSCSI mode to single path.
  1999. //
  2000. if (--mPrivate->MpioCount == 0) {
  2001. mPrivate->EnableMpio = FALSE;
  2002. }
  2003. } else if (AttemptConfigData->SessionConfigData.Enabled == ISCSI_ENABLED) {
  2004. if (mPrivate->SinglePathCount < 1) {
  2005. Status = EFI_ABORTED;
  2006. goto Error;
  2007. }
  2008. mPrivate->SinglePathCount--;
  2009. }
  2010. AttemptConfigIndex = AttemptConfigData->AttemptConfigIndex;
  2011. FreePool (AttemptConfigData);
  2012. //
  2013. // Create a new Attempt
  2014. //
  2015. AttemptConfigData = AllocateZeroPool (sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA));
  2016. if (AttemptConfigData == NULL) {
  2017. return EFI_OUT_OF_RESOURCES;
  2018. }
  2019. ConfigData = &AttemptConfigData->SessionConfigData;
  2020. ConfigData->TargetPort = ISCSI_WELL_KNOWN_PORT;
  2021. ConfigData->ConnectTimeout = CONNECT_DEFAULT_TIMEOUT;
  2022. ConfigData->ConnectRetryCount = CONNECT_MIN_RETRY;
  2023. AttemptConfigData->AuthenticationType = ISCSI_AUTH_TYPE_CHAP;
  2024. AttemptConfigData->AuthConfigData.CHAP.CHAPType = ISCSI_CHAP_UNI;
  2025. //
  2026. // Configure the Attempt index and set variable.
  2027. //
  2028. AttemptConfigData->AttemptConfigIndex = AttemptConfigIndex;
  2029. //
  2030. // Set the attempt name to default.
  2031. //
  2032. UnicodeSPrint (
  2033. mPrivate->PortString,
  2034. (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
  2035. L"Attempt %d",
  2036. (UINTN) AttemptConfigData->AttemptConfigIndex
  2037. );
  2038. UnicodeStrToAsciiStrS (mPrivate->PortString, AttemptConfigData->AttemptName, ATTEMPT_NAME_SIZE);
  2039. gRT->SetVariable (
  2040. mPrivate->PortString,
  2041. &gEfiIScsiInitiatorNameProtocolGuid,
  2042. ISCSI_CONFIG_VAR_ATTR,
  2043. sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA),
  2044. AttemptConfigData
  2045. );
  2046. //
  2047. // Mark the attempt order in NVR to be deleted - 0.
  2048. //
  2049. for (NewIndex = 0; NewIndex < Total; NewIndex++) {
  2050. if (AttemptConfigOrder[NewIndex] == AttemptConfigData->AttemptConfigIndex) {
  2051. AttemptConfigOrder[NewIndex] = 0;
  2052. break;
  2053. }
  2054. }
  2055. NewTotal--;
  2056. if (mCallbackInfo->Current == AttemptConfigData) {
  2057. mCallbackInfo->Current = NULL;
  2058. }
  2059. FreePool (AttemptConfigData);
  2060. //
  2061. // Check next Attempt.
  2062. //
  2063. Index++;
  2064. }
  2065. //
  2066. // Construct AttemptNewOrder.
  2067. //
  2068. for (Index = 0, NewIndex = 0; Index < Total; Index++) {
  2069. if (AttemptConfigOrder[Index] != 0) {
  2070. AttemptNewOrder[NewIndex] = AttemptConfigOrder[Index];
  2071. NewIndex++;
  2072. }
  2073. }
  2074. Attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE;
  2075. //
  2076. // Update AttemptOrder in NVR.
  2077. //
  2078. Status = gRT->SetVariable (
  2079. L"AttemptOrder",
  2080. &gIScsiConfigGuid,
  2081. Attribute,
  2082. NewTotal * sizeof (UINT8),
  2083. AttemptNewOrder
  2084. );
  2085. Error:
  2086. if (AttemptConfigOrder != NULL) {
  2087. FreePool (AttemptConfigOrder);
  2088. }
  2089. if (AttemptNewOrder != NULL) {
  2090. FreePool (AttemptNewOrder);
  2091. }
  2092. return Status;
  2093. }
  2094. /**
  2095. Callback function when user presses "Delete Attempts".
  2096. @param[in] IfrNvData The IFR nv data.
  2097. @retval EFI_INVALID_PARAMETER Any parameter is invalid.
  2098. @retval EFI_BUFFER_TOO_SMALL The buffer in UpdateData is too small.
  2099. @retval EFI_SUCCESS The operation is completed successfully.
  2100. **/
  2101. EFI_STATUS
  2102. IScsiConfigDisplayDeleteAttempts (
  2103. IN ISCSI_CONFIG_IFR_NVDATA *IfrNvData
  2104. )
  2105. {
  2106. UINT8 *AttemptConfigOrder;
  2107. UINTN AttemptConfigOrderSize;
  2108. LIST_ENTRY *Entry;
  2109. ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;
  2110. UINT8 Index;
  2111. VOID *StartOpCodeHandle;
  2112. EFI_IFR_GUID_LABEL *StartLabel;
  2113. VOID *EndOpCodeHandle;
  2114. EFI_IFR_GUID_LABEL *EndLabel;
  2115. EFI_STATUS Status;
  2116. Status = IScsiCreateOpCode (
  2117. DELETE_ENTRY_LABEL,
  2118. &StartOpCodeHandle,
  2119. &StartLabel,
  2120. &EndOpCodeHandle,
  2121. &EndLabel
  2122. );
  2123. if (EFI_ERROR (Status)) {
  2124. return Status;
  2125. }
  2126. AttemptConfigOrder = IScsiGetVariableAndSize (
  2127. L"AttemptOrder",
  2128. &gIScsiConfigGuid,
  2129. &AttemptConfigOrderSize
  2130. );
  2131. if (AttemptConfigOrder != NULL) {
  2132. //
  2133. // Create the check box opcode to be deleted.
  2134. //
  2135. Index = 0;
  2136. NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {
  2137. AttemptConfigData = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
  2138. IfrNvData->DeleteAttemptList[Index] = 0x00;
  2139. HiiCreateCheckBoxOpCode(
  2140. StartOpCodeHandle,
  2141. (EFI_QUESTION_ID) (ATTEMPT_DEL_QUESTION_ID + Index),
  2142. CONFIGURATION_VARSTORE_ID,
  2143. (UINT16) (ATTEMPT_DEL_VAR_OFFSET + Index),
  2144. AttemptConfigData->AttemptTitleToken,
  2145. AttemptConfigData->AttemptTitleHelpToken,
  2146. 0,
  2147. 0,
  2148. NULL
  2149. );
  2150. Index++;
  2151. if (Index == ISCSI_MAX_ATTEMPTS_NUM) {
  2152. break;
  2153. }
  2154. }
  2155. FreePool (AttemptConfigOrder);
  2156. }
  2157. Status = HiiUpdateForm (
  2158. mCallbackInfo->RegisteredHandle, // HII handle
  2159. &gIScsiConfigGuid, // Formset GUID
  2160. FORMID_DELETE_FORM, // Form ID
  2161. StartOpCodeHandle, // Label for where to insert opcodes
  2162. EndOpCodeHandle // Replace data
  2163. );
  2164. HiiFreeOpCodeHandle (StartOpCodeHandle);
  2165. HiiFreeOpCodeHandle (EndOpCodeHandle);
  2166. return Status;
  2167. }
  2168. /**
  2169. Callback function when user presses "Change Attempt Order".
  2170. @retval EFI_INVALID_PARAMETER Any parameter is invalid.
  2171. @retval EFI_OUT_OF_RESOURCES Does not have sufficient resources to finish this
  2172. operation.
  2173. @retval EFI_SUCCESS The operation is completed successfully.
  2174. **/
  2175. EFI_STATUS
  2176. IScsiConfigDisplayOrderAttempts (
  2177. VOID
  2178. )
  2179. {
  2180. EFI_STATUS Status;
  2181. UINT8 Index;
  2182. LIST_ENTRY *Entry;
  2183. ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;
  2184. VOID *StartOpCodeHandle;
  2185. EFI_IFR_GUID_LABEL *StartLabel;
  2186. VOID *EndOpCodeHandle;
  2187. EFI_IFR_GUID_LABEL *EndLabel;
  2188. VOID *OptionsOpCodeHandle;
  2189. Status = IScsiCreateOpCode (
  2190. ORDER_ENTRY_LABEL,
  2191. &StartOpCodeHandle,
  2192. &StartLabel,
  2193. &EndOpCodeHandle,
  2194. &EndLabel
  2195. );
  2196. if (EFI_ERROR (Status)) {
  2197. return Status;
  2198. }
  2199. ASSERT (StartOpCodeHandle != NULL);
  2200. OptionsOpCodeHandle = NULL;
  2201. //
  2202. // If no attempt to be ordered, update the original form and exit.
  2203. //
  2204. if (mPrivate->AttemptCount == 0) {
  2205. goto Exit;
  2206. }
  2207. //
  2208. // Create Option OpCode.
  2209. //
  2210. OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();
  2211. if (OptionsOpCodeHandle == NULL) {
  2212. Status = EFI_OUT_OF_RESOURCES;
  2213. goto Error;
  2214. }
  2215. Index = 0;
  2216. NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {
  2217. AttemptConfigData = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
  2218. HiiCreateOneOfOptionOpCode (
  2219. OptionsOpCodeHandle,
  2220. AttemptConfigData->AttemptTitleToken,
  2221. 0,
  2222. EFI_IFR_NUMERIC_SIZE_1,
  2223. AttemptConfigData->AttemptConfigIndex
  2224. );
  2225. Index++;
  2226. }
  2227. ASSERT (Index == mPrivate->AttemptCount);
  2228. HiiCreateOrderedListOpCode (
  2229. StartOpCodeHandle, // Container for dynamic created opcodes
  2230. DYNAMIC_ORDERED_LIST_QUESTION_ID, // Question ID
  2231. CONFIGURATION_VARSTORE_ID, // VarStore ID
  2232. DYNAMIC_ORDERED_LIST_VAR_OFFSET, // Offset in Buffer Storage
  2233. STRING_TOKEN (STR_ORDER_ATTEMPT_ENTRY), // Question prompt text
  2234. STRING_TOKEN (STR_ORDER_ATTEMPT_ENTRY), // Question help text
  2235. 0, // Question flag
  2236. EFI_IFR_UNIQUE_SET, // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET
  2237. EFI_IFR_NUMERIC_SIZE_1, // Data type of Question value
  2238. ISCSI_MAX_ATTEMPTS_NUM, // Maximum container
  2239. OptionsOpCodeHandle, // Option Opcode list
  2240. NULL // Default Opcode is NULL
  2241. );
  2242. Exit:
  2243. Status = HiiUpdateForm (
  2244. mCallbackInfo->RegisteredHandle, // HII handle
  2245. &gIScsiConfigGuid, // Formset GUID
  2246. FORMID_ORDER_FORM, // Form ID
  2247. StartOpCodeHandle, // Label for where to insert opcodes
  2248. EndOpCodeHandle // Replace data
  2249. );
  2250. Error:
  2251. HiiFreeOpCodeHandle (StartOpCodeHandle);
  2252. HiiFreeOpCodeHandle (EndOpCodeHandle);
  2253. if (OptionsOpCodeHandle != NULL) {
  2254. HiiFreeOpCodeHandle (OptionsOpCodeHandle);
  2255. }
  2256. return Status;
  2257. }
  2258. /**
  2259. Callback function when user presses "Commit Changes and Exit" in Change Attempt Order or Change Attempt Order by Keyword.
  2260. @param[in] IfrNvData The IFR nv data.
  2261. @retval EFI_OUT_OF_RESOURCES Does not have sufficient resources to finish this
  2262. operation.
  2263. @retval EFI_NOT_FOUND Cannot find the corresponding variable.
  2264. @retval EFI_SUCCESS The operation is completed successfully.
  2265. **/
  2266. EFI_STATUS
  2267. IScsiConfigOrderAttempts (
  2268. IN ISCSI_CONFIG_IFR_NVDATA *IfrNvData
  2269. )
  2270. {
  2271. EFI_STATUS Status;
  2272. UINTN Index;
  2273. UINTN Indexj;
  2274. UINT8 AttemptConfigIndex;
  2275. ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;
  2276. UINT8 *AttemptConfigOrder;
  2277. UINT8 *AttemptConfigOrderTmp;
  2278. UINTN AttemptConfigOrderSize;
  2279. AttemptConfigOrder = IScsiGetVariableAndSize (
  2280. L"AttemptOrder",
  2281. &gIScsiConfigGuid,
  2282. &AttemptConfigOrderSize
  2283. );
  2284. if (AttemptConfigOrder == NULL) {
  2285. return EFI_NOT_FOUND;
  2286. }
  2287. AttemptConfigOrderTmp = AllocateZeroPool (AttemptConfigOrderSize);
  2288. if (AttemptConfigOrderTmp == NULL) {
  2289. Status = EFI_OUT_OF_RESOURCES;
  2290. goto Exit;
  2291. }
  2292. for (Index = 0; Index < ISCSI_MAX_ATTEMPTS_NUM; Index++) {
  2293. //
  2294. // The real content ends with 0.
  2295. //
  2296. if (IfrNvData->DynamicOrderedList[Index] == 0) {
  2297. break;
  2298. }
  2299. AttemptConfigIndex = IfrNvData->DynamicOrderedList[Index];
  2300. AttemptConfigData = IScsiConfigGetAttemptByConfigIndex (AttemptConfigIndex);
  2301. if (AttemptConfigData == NULL) {
  2302. Status = EFI_NOT_FOUND;
  2303. goto Exit;
  2304. }
  2305. //
  2306. // Reorder the Attempt List.
  2307. //
  2308. RemoveEntryList (&AttemptConfigData->Link);
  2309. InsertTailList (&mPrivate->AttemptConfigs, &AttemptConfigData->Link);
  2310. AttemptConfigOrderTmp[Index] = AttemptConfigIndex;
  2311. //
  2312. // Mark it to be deleted - 0.
  2313. //
  2314. for (Indexj = 0; Indexj < AttemptConfigOrderSize / sizeof (UINT8); Indexj++) {
  2315. if (AttemptConfigOrder[Indexj] == AttemptConfigIndex) {
  2316. AttemptConfigOrder[Indexj] = 0;
  2317. break;
  2318. }
  2319. }
  2320. }
  2321. //
  2322. // Adjust the attempt order in NVR.
  2323. //
  2324. for (; Index < AttemptConfigOrderSize / sizeof (UINT8); Index++) {
  2325. for (Indexj = 0; Indexj < AttemptConfigOrderSize / sizeof (UINT8); Indexj++) {
  2326. if (AttemptConfigOrder[Indexj] != 0) {
  2327. AttemptConfigOrderTmp[Index] = AttemptConfigOrder[Indexj];
  2328. AttemptConfigOrder[Indexj] = 0;
  2329. continue;
  2330. }
  2331. }
  2332. }
  2333. Status = gRT->SetVariable (
  2334. L"AttemptOrder",
  2335. &gIScsiConfigGuid,
  2336. EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
  2337. AttemptConfigOrderSize,
  2338. AttemptConfigOrderTmp
  2339. );
  2340. Exit:
  2341. if (AttemptConfigOrderTmp != NULL) {
  2342. FreePool (AttemptConfigOrderTmp);
  2343. }
  2344. FreePool (AttemptConfigOrder);
  2345. return Status;
  2346. }
  2347. /**
  2348. Callback function when a user presses "Attempt *" or when a user selects a NIC to
  2349. create the new attempt.
  2350. @param[in] KeyValue A unique value which is sent to the original
  2351. exporting driver so that it can identify the type
  2352. of data to expect.
  2353. @param[in] IfrNvData The IFR nv data.
  2354. @retval EFI_OUT_OF_RESOURCES Does not have sufficient resources to finish this
  2355. operation.
  2356. @retval EFI_NOT_FOUND Cannot find the corresponding variable.
  2357. @retval EFI_UNSUPPORTED Can not create more attempts.
  2358. @retval EFI_SUCCESS The operation is completed successfully.
  2359. **/
  2360. EFI_STATUS
  2361. IScsiConfigProcessDefault (
  2362. IN EFI_QUESTION_ID KeyValue,
  2363. IN ISCSI_CONFIG_IFR_NVDATA *IfrNvData
  2364. )
  2365. {
  2366. BOOLEAN NewAttempt;
  2367. ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;
  2368. UINT8 CurrentAttemptConfigIndex;
  2369. ISCSI_NIC_INFO *NicInfo;
  2370. UINT8 NicIndex;
  2371. CHAR16 MacString[ISCSI_MAX_MAC_STRING_LEN];
  2372. UINT8 *AttemptConfigOrder;
  2373. UINTN AttemptConfigOrderSize;
  2374. UINTN Index;
  2375. EFI_INPUT_KEY Key;
  2376. AttemptConfigData = NULL;
  2377. //
  2378. // Is User creating a new attempt?
  2379. //
  2380. NewAttempt = FALSE;
  2381. if ((KeyValue >= KEY_MAC_ENTRY_BASE) &&
  2382. (KeyValue <= (UINT16) (mPrivate->MaxNic + KEY_MAC_ENTRY_BASE))) {
  2383. //
  2384. // User has pressed "Add an Attempt" and then selects a NIC.
  2385. //
  2386. NewAttempt = TRUE;
  2387. } else if ((KeyValue >= KEY_ATTEMPT_ENTRY_BASE) &&
  2388. (KeyValue < (ISCSI_MAX_ATTEMPTS_NUM + KEY_ATTEMPT_ENTRY_BASE))) {
  2389. //
  2390. // User has pressed "Attempt *".
  2391. //
  2392. NewAttempt = FALSE;
  2393. } else {
  2394. //
  2395. // Don't process anything.
  2396. //
  2397. return EFI_SUCCESS;
  2398. }
  2399. if (NewAttempt) {
  2400. //
  2401. // Determine which NIC user has selected for the new created attempt.
  2402. //
  2403. NicIndex = (UINT8) (KeyValue - KEY_MAC_ENTRY_BASE);
  2404. NicInfo = IScsiGetNicInfoByIndex (NicIndex);
  2405. if (NicInfo == NULL) {
  2406. return EFI_NOT_FOUND;
  2407. }
  2408. //
  2409. // Create an attempt following the initialized attempt order.
  2410. //
  2411. AttemptConfigOrder = IScsiGetVariableAndSize (
  2412. L"InitialAttemptOrder",
  2413. &gIScsiConfigGuid,
  2414. &AttemptConfigOrderSize
  2415. );
  2416. if (AttemptConfigOrder == NULL) {
  2417. return EFI_NOT_FOUND;
  2418. }
  2419. for (Index = 0; Index < AttemptConfigOrderSize / sizeof (UINT8); Index++) {
  2420. UnicodeSPrint (
  2421. mPrivate->PortString,
  2422. (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
  2423. L"Attempt %d",
  2424. (UINTN) AttemptConfigOrder[Index]
  2425. );
  2426. GetVariable2 (
  2427. mPrivate->PortString,
  2428. &gEfiIScsiInitiatorNameProtocolGuid,
  2429. (VOID**)&AttemptConfigData,
  2430. NULL
  2431. );
  2432. if (AttemptConfigData == NULL || AttemptConfigData->Actived == ISCSI_ACTIVE_ENABLED) {
  2433. continue;
  2434. }
  2435. break;
  2436. }
  2437. if (Index > PcdGet8 (PcdMaxIScsiAttemptNumber)) {
  2438. CreatePopUp (
  2439. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  2440. &Key,
  2441. L"Can not create more attempts, Please configure the PcdMaxIScsiAttemptNumber if needed!",
  2442. NULL
  2443. );
  2444. return EFI_UNSUPPORTED;
  2445. }
  2446. if (AttemptConfigOrder != NULL) {
  2447. FreePool (AttemptConfigOrder);
  2448. }
  2449. //
  2450. // Record the MAC info in Config Data.
  2451. //
  2452. IScsiMacAddrToStr (
  2453. &NicInfo->PermanentAddress,
  2454. NicInfo->HwAddressSize,
  2455. NicInfo->VlanId,
  2456. MacString
  2457. );
  2458. ASSERT (AttemptConfigData != NULL);
  2459. UnicodeStrToAsciiStrS (MacString, AttemptConfigData->MacString, sizeof (AttemptConfigData->MacString));
  2460. AttemptConfigData->NicIndex = NicIndex;
  2461. AttemptConfigData->Actived = ISCSI_ACTIVE_ENABLED;
  2462. //
  2463. // Generate OUI-format ISID based on MAC address.
  2464. //
  2465. CopyMem (AttemptConfigData->SessionConfigData.IsId, &NicInfo->PermanentAddress, 6);
  2466. AttemptConfigData->SessionConfigData.IsId[0] =
  2467. (UINT8) (AttemptConfigData->SessionConfigData.IsId[0] & 0x3F);
  2468. //
  2469. // Add the help info for the new attempt.
  2470. //
  2471. UnicodeSPrint (
  2472. mPrivate->PortString,
  2473. (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
  2474. L"MAC: %s, PFA: Bus %d | Dev %d | Func %d",
  2475. MacString,
  2476. NicInfo->BusNumber,
  2477. NicInfo->DeviceNumber,
  2478. NicInfo->FunctionNumber
  2479. );
  2480. AttemptConfigData->AttemptTitleHelpToken = HiiSetString (
  2481. mCallbackInfo->RegisteredHandle,
  2482. 0,
  2483. mPrivate->PortString,
  2484. NULL
  2485. );
  2486. if (AttemptConfigData->AttemptTitleHelpToken == 0) {
  2487. FreePool (AttemptConfigData);
  2488. return EFI_OUT_OF_RESOURCES;
  2489. }
  2490. } else {
  2491. //
  2492. // Determine which Attempt user has selected to configure.
  2493. // Get the attempt configuration data.
  2494. //
  2495. CurrentAttemptConfigIndex = (UINT8) (KeyValue - KEY_ATTEMPT_ENTRY_BASE);
  2496. AttemptConfigData = IScsiConfigGetAttemptByConfigIndex (CurrentAttemptConfigIndex);
  2497. if (AttemptConfigData == NULL) {
  2498. DEBUG ((DEBUG_ERROR, "Corresponding configuration data can not be retrieved!\n"));
  2499. return EFI_NOT_FOUND;
  2500. }
  2501. }
  2502. //
  2503. // Clear the old IFR data to avoid sharing it with other attempts.
  2504. //
  2505. if (IfrNvData->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {
  2506. ZeroMem (IfrNvData->CHAPName, sizeof (IfrNvData->CHAPName));
  2507. ZeroMem (IfrNvData->CHAPSecret, sizeof (IfrNvData->CHAPSecret));
  2508. ZeroMem (IfrNvData->ReverseCHAPName, sizeof (IfrNvData->ReverseCHAPName));
  2509. ZeroMem (IfrNvData->ReverseCHAPSecret, sizeof (IfrNvData->ReverseCHAPSecret));
  2510. }
  2511. IScsiConvertAttemptConfigDataToIfrNvData (AttemptConfigData, IfrNvData);
  2512. //
  2513. // Update current attempt to be a new created attempt or an existing attempt.
  2514. //
  2515. mCallbackInfo->Current = AttemptConfigData;
  2516. return EFI_SUCCESS;
  2517. }
  2518. /**
  2519. This function allows the caller to request the current
  2520. configuration for one or more named elements. The resulting
  2521. string is in <ConfigAltResp> format. Also, any and all alternative
  2522. configuration strings shall be appended to the end of the
  2523. current configuration string. If they are, they must appear
  2524. after the current configuration. They must contain the same
  2525. routing (GUID, NAME, PATH) as the current configuration string.
  2526. They must have an additional description indicating the type of
  2527. alternative configuration the string represents,
  2528. "ALTCFG=<StringToken>". That <StringToken> (when
  2529. converted from Hex UNICODE to binary) is a reference to a
  2530. string in the associated string pack.
  2531. @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
  2532. @param[in] Request A null-terminated Unicode string in
  2533. <ConfigRequest> format. Note that this
  2534. includes the routing information as well as
  2535. the configurable name / value pairs. It is
  2536. invalid for this string to be in
  2537. <MultiConfigRequest> format.
  2538. @param[out] Progress On return, points to a character in the
  2539. Request string. Points to the string's null
  2540. terminator if request was successful. Points
  2541. to the most recent "&" before the first
  2542. failing name / value pair (or the beginning
  2543. of the string if the failure is in the first
  2544. name / value pair) if the request was not successful.
  2545. @param[out] Results A null-terminated Unicode string in
  2546. <ConfigAltResp> format which has all values
  2547. filled in for the names in the Request string.
  2548. String to be allocated by the called function.
  2549. @retval EFI_SUCCESS The Results string is filled with the
  2550. values corresponding to all requested
  2551. names.
  2552. @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
  2553. parts of the results that must be
  2554. stored awaiting possible future
  2555. protocols.
  2556. @retval EFI_INVALID_PARAMETER For example, passing in a NULL
  2557. for the Request parameter
  2558. would result in this type of
  2559. error. In this case, the
  2560. Progress parameter would be
  2561. set to NULL.
  2562. @retval EFI_NOT_FOUND Routing data doesn't match any
  2563. known driver. Progress set to the
  2564. first character in the routing header.
  2565. Note: There is no requirement that the
  2566. driver validate the routing data. It
  2567. must skip the <ConfigHdr> in order to
  2568. process the names.
  2569. @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set
  2570. to most recent "&" before the
  2571. error or the beginning of the
  2572. string.
  2573. @retval EFI_INVALID_PARAMETER Unknown name. Progress points
  2574. to the & before the name in
  2575. question.
  2576. **/
  2577. EFI_STATUS
  2578. EFIAPI
  2579. IScsiFormExtractConfig (
  2580. IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
  2581. IN CONST EFI_STRING Request,
  2582. OUT EFI_STRING *Progress,
  2583. OUT EFI_STRING *Results
  2584. )
  2585. {
  2586. EFI_STATUS Status;
  2587. CHAR8 *InitiatorName;
  2588. UINTN BufferSize;
  2589. ISCSI_CONFIG_IFR_NVDATA *IfrNvData;
  2590. ISCSI_FORM_CALLBACK_INFO *Private;
  2591. EFI_STRING ConfigRequestHdr;
  2592. EFI_STRING ConfigRequest;
  2593. BOOLEAN AllocatedRequest;
  2594. UINTN Size;
  2595. if (This == NULL || Progress == NULL || Results == NULL) {
  2596. return EFI_INVALID_PARAMETER;
  2597. }
  2598. *Progress = Request;
  2599. if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &gIScsiConfigGuid, mVendorStorageName)) {
  2600. return EFI_NOT_FOUND;
  2601. }
  2602. ConfigRequestHdr = NULL;
  2603. ConfigRequest = NULL;
  2604. AllocatedRequest = FALSE;
  2605. Size = 0;
  2606. Private = ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This);
  2607. IfrNvData = AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA));
  2608. if (IfrNvData == NULL) {
  2609. return EFI_OUT_OF_RESOURCES;
  2610. }
  2611. if (Private->Current!= NULL) {
  2612. IScsiConvertAttemptConfigDataToIfrNvData (Private->Current, IfrNvData);
  2613. }
  2614. //
  2615. // Extract all AttemptConfigData to Keyword stroage of IfrNvData.
  2616. //
  2617. IScsiConvertAttemptConfigDataToIfrNvDataByKeyword (IfrNvData);
  2618. BufferSize = ISCSI_NAME_MAX_SIZE;
  2619. InitiatorName = (CHAR8 *) AllocateZeroPool (BufferSize);
  2620. if (InitiatorName == NULL) {
  2621. FreePool (IfrNvData);
  2622. return EFI_OUT_OF_RESOURCES;
  2623. }
  2624. Status = gIScsiInitiatorName.Get (&gIScsiInitiatorName, &BufferSize, InitiatorName);
  2625. if (EFI_ERROR (Status)) {
  2626. IfrNvData->InitiatorName[0] = L'\0';
  2627. } else {
  2628. AsciiStrToUnicodeStrS (
  2629. InitiatorName,
  2630. IfrNvData->InitiatorName,
  2631. sizeof (IfrNvData->InitiatorName) / sizeof (IfrNvData->InitiatorName[0])
  2632. );
  2633. }
  2634. //
  2635. // Convert buffer data to <ConfigResp> by helper function BlockToConfig().
  2636. //
  2637. BufferSize = sizeof (ISCSI_CONFIG_IFR_NVDATA);
  2638. ConfigRequest = Request;
  2639. if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {
  2640. //
  2641. // Request has no request element, construct full request string.
  2642. // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
  2643. // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
  2644. //
  2645. ConfigRequestHdr = HiiConstructConfigHdr (&gIScsiConfigGuid, mVendorStorageName, Private->DriverHandle);
  2646. Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
  2647. ConfigRequest = AllocateZeroPool (Size);
  2648. if (ConfigRequest == NULL) {
  2649. FreePool (IfrNvData);
  2650. FreePool (InitiatorName);
  2651. return EFI_OUT_OF_RESOURCES;
  2652. }
  2653. AllocatedRequest = TRUE;
  2654. UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
  2655. FreePool (ConfigRequestHdr);
  2656. }
  2657. Status = gHiiConfigRouting->BlockToConfig (
  2658. gHiiConfigRouting,
  2659. ConfigRequest,
  2660. (UINT8 *) IfrNvData,
  2661. BufferSize,
  2662. Results,
  2663. Progress
  2664. );
  2665. FreePool (IfrNvData);
  2666. FreePool (InitiatorName);
  2667. //
  2668. // Free the allocated config request string.
  2669. //
  2670. if (AllocatedRequest) {
  2671. FreePool (ConfigRequest);
  2672. ConfigRequest = NULL;
  2673. }
  2674. //
  2675. // Set Progress string to the original request string.
  2676. //
  2677. if (Request == NULL) {
  2678. *Progress = NULL;
  2679. } else if (StrStr (Request, L"OFFSET") == NULL) {
  2680. *Progress = Request + StrLen (Request);
  2681. }
  2682. return Status;
  2683. }
  2684. /**
  2685. This function applies changes in a driver's configuration.
  2686. Input is a Configuration, which has the routing data for this
  2687. driver followed by name / value configuration pairs. The driver
  2688. must apply those pairs to its configurable storage. If the
  2689. driver's configuration is stored in a linear block of data
  2690. and the driver's name / value pairs are in <BlockConfig>
  2691. format, it may use the ConfigToBlock helper function (above) to
  2692. simplify the job.
  2693. @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
  2694. @param[in] Configuration A null-terminated Unicode string in
  2695. <ConfigString> format.
  2696. @param[out] Progress A pointer to a string filled in with the
  2697. offset of the most recent '&' before the
  2698. first failing name / value pair (or the
  2699. beginning of the string if the failure
  2700. is in the first name / value pair) or
  2701. the terminating NULL if all was
  2702. successful.
  2703. @retval EFI_SUCCESS The results have been distributed or are
  2704. awaiting distribution.
  2705. @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
  2706. parts of the results that must be
  2707. stored awaiting possible future
  2708. protocols.
  2709. @retval EFI_INVALID_PARAMETERS Passing in a NULL for the
  2710. Results parameter would result
  2711. in this type of error.
  2712. @retval EFI_NOT_FOUND Target for the specified routing data
  2713. was not found.
  2714. **/
  2715. EFI_STATUS
  2716. EFIAPI
  2717. IScsiFormRouteConfig (
  2718. IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
  2719. IN CONST EFI_STRING Configuration,
  2720. OUT EFI_STRING *Progress
  2721. )
  2722. {
  2723. EFI_STATUS Status;
  2724. ISCSI_CONFIG_IFR_NVDATA *IfrNvData;
  2725. ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;
  2726. LIST_ENTRY *Entry;
  2727. LIST_ENTRY *NextEntry;
  2728. ISCSI_NIC_INFO *NicInfo;
  2729. EFI_INPUT_KEY Key;
  2730. CHAR16 MacString[ISCSI_MAX_MAC_STRING_LEN];
  2731. CHAR8 *InitiatorName;
  2732. UINT8 *AttemptList;
  2733. UINTN BufferSize;
  2734. UINTN OffSet;
  2735. UINTN Index;
  2736. UINTN Index2;
  2737. Index = 0;
  2738. Index2 = 0;
  2739. NicInfo = NULL;
  2740. AttemptList = NULL;
  2741. Status = EFI_SUCCESS;
  2742. if (This == NULL || Configuration == NULL || Progress == NULL) {
  2743. return EFI_INVALID_PARAMETER;
  2744. }
  2745. //
  2746. // Check routing data in <ConfigHdr>.
  2747. // Note: if only one Storage is used, then this checking could be skipped.
  2748. //
  2749. if (!HiiIsConfigHdrMatch (Configuration, &gIScsiConfigGuid, mVendorStorageName)) {
  2750. *Progress = Configuration;
  2751. return EFI_NOT_FOUND;
  2752. }
  2753. IfrNvData = AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA));
  2754. if (IfrNvData == NULL) {
  2755. return EFI_OUT_OF_RESOURCES;
  2756. }
  2757. BufferSize = ISCSI_NAME_MAX_SIZE;
  2758. InitiatorName = (CHAR8 *) AllocateZeroPool (BufferSize);
  2759. if (InitiatorName == NULL) {
  2760. Status = EFI_OUT_OF_RESOURCES;
  2761. goto Exit;
  2762. }
  2763. //
  2764. // Convert <ConfigResp> to buffer data by helper function ConfigToBlock().
  2765. //
  2766. BufferSize = sizeof (ISCSI_CONFIG_IFR_NVDATA);
  2767. Status = gHiiConfigRouting->ConfigToBlock (
  2768. gHiiConfigRouting,
  2769. Configuration,
  2770. (UINT8 *) IfrNvData,
  2771. &BufferSize,
  2772. Progress
  2773. );
  2774. if (EFI_ERROR (Status)) {
  2775. goto Exit;
  2776. }
  2777. if (IfrNvData->InitiatorName[0] != L'\0') {
  2778. UnicodeStrToAsciiStrS (IfrNvData->InitiatorName, InitiatorName, ISCSI_NAME_MAX_SIZE);
  2779. BufferSize = AsciiStrSize (InitiatorName);
  2780. Status = gIScsiInitiatorName.Set (&gIScsiInitiatorName, &BufferSize, InitiatorName);
  2781. if (EFI_ERROR (Status)) {
  2782. CreatePopUp (
  2783. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  2784. &Key,
  2785. L"Invalid iSCSI Name!",
  2786. NULL
  2787. );
  2788. goto Exit;
  2789. }
  2790. } else {
  2791. Status = IScsiGetValue (Configuration, L"&OFFSET=", &OffSet);
  2792. if (EFI_ERROR (Status)) {
  2793. goto Exit;
  2794. }
  2795. if (OffSet >= ATTEMPT_MAC_ADDR_VAR_OFFSET) {
  2796. Status = gIScsiInitiatorName.Get (&gIScsiInitiatorName, &BufferSize, InitiatorName);
  2797. if (EFI_ERROR (Status)) {
  2798. CreatePopUp (
  2799. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  2800. &Key,
  2801. L"Error: please configure iSCSI initiator name first!",
  2802. NULL
  2803. );
  2804. goto Exit;
  2805. }
  2806. } else {
  2807. goto Exit;
  2808. }
  2809. if (IfrNvData->ISCSIAddAttemptList[0] != L'\0') {
  2810. Status =IScsiGetAttemptIndexList (IfrNvData->ISCSIAddAttemptList, IfrNvData->AddAttemptList, TRUE);
  2811. if (EFI_ERROR (Status)) {
  2812. CreatePopUp (
  2813. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  2814. &Key,
  2815. L"Error: The add attempt list is invalid",
  2816. NULL
  2817. );
  2818. goto Exit;
  2819. }
  2820. Status = IScsiConfigAddAttemptsByKeywords (IfrNvData->AddAttemptList);
  2821. if (EFI_ERROR (Status)) {
  2822. goto Exit;
  2823. }
  2824. } else if (IfrNvData->ISCSIDeleteAttemptList[0] != L'\0') {
  2825. AttemptList =(UINT8 *) AllocateZeroPool ((ISCSI_MAX_ATTEMPTS_NUM + 1) * sizeof (UINT8));
  2826. if (AttemptList == NULL) {
  2827. Status = EFI_OUT_OF_RESOURCES;
  2828. goto Exit;
  2829. }
  2830. Status = IScsiGetAttemptIndexList (IfrNvData->ISCSIDeleteAttemptList, AttemptList, FALSE);
  2831. if (EFI_ERROR (Status)) {
  2832. CreatePopUp (
  2833. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  2834. &Key,
  2835. L"Error: The delete attempt list is invalid",
  2836. NULL
  2837. );
  2838. goto Exit;
  2839. }
  2840. //
  2841. // Mark the attempt which will be delete in the global list.
  2842. //
  2843. NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &mPrivate->AttemptConfigs) {
  2844. AttemptConfigData = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
  2845. while (AttemptList[Index] != 0) {
  2846. if (AttemptConfigData->AttemptConfigIndex == AttemptList[Index]) {
  2847. IfrNvData->DeleteAttemptList[Index2] = 1;
  2848. break;
  2849. }
  2850. Index ++;
  2851. }
  2852. Index2 ++;
  2853. Index = 0;
  2854. }
  2855. Status = IScsiConfigDeleteAttempts (IfrNvData);
  2856. if (EFI_ERROR (Status)) {
  2857. goto Exit;
  2858. }
  2859. FreePool (AttemptList);
  2860. } else if (IfrNvData->ISCSIAttemptOrder[0] != L'\0') {
  2861. Status = IScsiGetAttemptIndexList (IfrNvData->ISCSIAttemptOrder, IfrNvData->DynamicOrderedList, FALSE);
  2862. if (EFI_ERROR (Status)) {
  2863. CreatePopUp (
  2864. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  2865. &Key,
  2866. L"Error: The new attempt order list is invalid",
  2867. NULL
  2868. );
  2869. goto Exit;
  2870. }
  2871. Status = IScsiConfigOrderAttempts (IfrNvData);
  2872. if (EFI_ERROR (Status)) {
  2873. goto Exit;
  2874. }
  2875. } else if (IfrNvData->ISCSIMacAddr[0] != L'\0') {
  2876. NET_LIST_FOR_EACH (Entry, &mPrivate->NicInfoList) {
  2877. NicInfo = NET_LIST_USER_STRUCT (Entry, ISCSI_NIC_INFO, Link);
  2878. IScsiMacAddrToStr (
  2879. &NicInfo->PermanentAddress,
  2880. NicInfo->HwAddressSize,
  2881. NicInfo->VlanId,
  2882. MacString
  2883. );
  2884. if (!StrCmp(MacString, IfrNvData->ISCSIMacAddr)) {
  2885. mPrivate->CurrentNic = NicInfo->NicIndex;
  2886. break;
  2887. }
  2888. }
  2889. if ((NicInfo == NULL) || (NicInfo->NicIndex == 0)) {
  2890. Status = EFI_NOT_FOUND;
  2891. goto Exit;
  2892. }
  2893. } else {
  2894. Status = IScsiConvertlfrNvDataToAttemptConfigDataByKeyword (IfrNvData, OffSet);
  2895. if (EFI_ERROR (Status)) {
  2896. goto Exit;
  2897. }
  2898. }
  2899. }
  2900. IScsiConfigUpdateAttempt ();
  2901. Exit:
  2902. if (InitiatorName != NULL) {
  2903. FreePool (InitiatorName);
  2904. }
  2905. if (IfrNvData != NULL) {
  2906. FreePool (IfrNvData);
  2907. }
  2908. return Status;
  2909. }
  2910. /**
  2911. This function is called to provide results data to the driver.
  2912. This data consists of a unique key that is used to identify
  2913. which data is either being passed back or being asked for.
  2914. @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
  2915. @param[in] Action Specifies the type of action taken by the browser.
  2916. @param[in] QuestionId A unique value which is sent to the original
  2917. exporting driver so that it can identify the type
  2918. of data to expect. The format of the data tends to
  2919. vary based on the opcode that generated the callback.
  2920. @param[in] Type The type of value for the question.
  2921. @param[in, out] Value A pointer to the data being sent to the original
  2922. exporting driver.
  2923. @param[out] ActionRequest On return, points to the action requested by the
  2924. callback function.
  2925. @retval EFI_SUCCESS The callback successfully handled the action.
  2926. @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
  2927. variable and its data.
  2928. @retval EFI_DEVICE_ERROR The variable could not be saved.
  2929. @retval EFI_UNSUPPORTED The specified Action is not supported by the
  2930. callback.
  2931. **/
  2932. EFI_STATUS
  2933. EFIAPI
  2934. IScsiFormCallback (
  2935. IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
  2936. IN EFI_BROWSER_ACTION Action,
  2937. IN EFI_QUESTION_ID QuestionId,
  2938. IN UINT8 Type,
  2939. IN OUT EFI_IFR_TYPE_VALUE *Value,
  2940. OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
  2941. )
  2942. {
  2943. ISCSI_FORM_CALLBACK_INFO *Private;
  2944. UINTN BufferSize;
  2945. CHAR8 *IScsiName;
  2946. CHAR8 IpString[ISCSI_NAME_MAX_SIZE];
  2947. CHAR8 LunString[ISCSI_LUN_STR_MAX_LEN];
  2948. UINT64 Lun;
  2949. EFI_IP_ADDRESS HostIp;
  2950. EFI_IP_ADDRESS SubnetMask;
  2951. EFI_IP_ADDRESS Gateway;
  2952. ISCSI_CONFIG_IFR_NVDATA *IfrNvData;
  2953. ISCSI_CONFIG_IFR_NVDATA OldIfrNvData;
  2954. EFI_STATUS Status;
  2955. EFI_INPUT_KEY Key;
  2956. ISCSI_NIC_INFO *NicInfo;
  2957. NicInfo = NULL;
  2958. if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) {
  2959. //
  2960. // Do nothing for UEFI OPEN/CLOSE Action
  2961. //
  2962. return EFI_SUCCESS;
  2963. }
  2964. if ((Action != EFI_BROWSER_ACTION_CHANGING) && (Action != EFI_BROWSER_ACTION_CHANGED)) {
  2965. //
  2966. // All other type return unsupported.
  2967. //
  2968. return EFI_UNSUPPORTED;
  2969. }
  2970. if ((Value == NULL) || (ActionRequest == NULL)) {
  2971. return EFI_INVALID_PARAMETER;
  2972. }
  2973. Private = ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This);
  2974. //
  2975. // Retrieve uncommitted data from Browser
  2976. //
  2977. BufferSize = sizeof (ISCSI_CONFIG_IFR_NVDATA);
  2978. IfrNvData = AllocateZeroPool (BufferSize);
  2979. if (IfrNvData == NULL) {
  2980. return EFI_OUT_OF_RESOURCES;
  2981. }
  2982. IScsiName = (CHAR8 *) AllocateZeroPool (ISCSI_NAME_MAX_SIZE);
  2983. if (IScsiName == NULL) {
  2984. FreePool (IfrNvData);
  2985. return EFI_OUT_OF_RESOURCES;
  2986. }
  2987. Status = EFI_SUCCESS;
  2988. ZeroMem (&OldIfrNvData, BufferSize);
  2989. HiiGetBrowserData (NULL, NULL, BufferSize, (UINT8 *) IfrNvData);
  2990. CopyMem (&OldIfrNvData, IfrNvData, BufferSize);
  2991. if (Action == EFI_BROWSER_ACTION_CHANGING) {
  2992. switch (QuestionId) {
  2993. case KEY_ADD_ATTEMPT:
  2994. //
  2995. // Check whether iSCSI initiator name is configured already.
  2996. //
  2997. mPrivate->InitiatorNameLength = ISCSI_NAME_MAX_SIZE;
  2998. Status = gIScsiInitiatorName.Get (
  2999. &gIScsiInitiatorName,
  3000. &mPrivate->InitiatorNameLength,
  3001. mPrivate->InitiatorName
  3002. );
  3003. if (EFI_ERROR (Status)) {
  3004. CreatePopUp (
  3005. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  3006. &Key,
  3007. L"Error: please configure iSCSI initiator name first!",
  3008. NULL
  3009. );
  3010. break;
  3011. }
  3012. Status = IScsiConfigAddAttempt ();
  3013. break;
  3014. case KEY_DELETE_ATTEMPT:
  3015. CopyMem (
  3016. OldIfrNvData.DeleteAttemptList,
  3017. IfrNvData->DeleteAttemptList,
  3018. sizeof (IfrNvData->DeleteAttemptList)
  3019. );
  3020. Status = IScsiConfigDisplayDeleteAttempts (IfrNvData);
  3021. break;
  3022. case KEY_ORDER_ATTEMPT_CONFIG:
  3023. //
  3024. // Order the attempt according to user input.
  3025. //
  3026. CopyMem (
  3027. OldIfrNvData.DynamicOrderedList,
  3028. IfrNvData->DynamicOrderedList,
  3029. sizeof (IfrNvData->DynamicOrderedList)
  3030. );
  3031. IScsiConfigDisplayOrderAttempts ();
  3032. break;
  3033. default:
  3034. Status = IScsiConfigProcessDefault (QuestionId, IfrNvData);
  3035. break;
  3036. }
  3037. } else if (Action == EFI_BROWSER_ACTION_CHANGED) {
  3038. switch (QuestionId) {
  3039. case KEY_INITIATOR_NAME:
  3040. UnicodeStrToAsciiStrS (IfrNvData->InitiatorName, IScsiName, ISCSI_NAME_MAX_SIZE);
  3041. BufferSize = AsciiStrSize (IScsiName);
  3042. Status = gIScsiInitiatorName.Set (&gIScsiInitiatorName, &BufferSize, IScsiName);
  3043. if (EFI_ERROR (Status)) {
  3044. CreatePopUp (
  3045. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  3046. &Key,
  3047. L"Invalid iSCSI Name!",
  3048. NULL
  3049. );
  3050. }
  3051. *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
  3052. break;
  3053. case KEY_SAVE_ATTEMPT_CONFIG:
  3054. Status = IScsiConvertIfrNvDataToAttemptConfigData (IfrNvData, Private->Current);
  3055. if (EFI_ERROR (Status)) {
  3056. break;
  3057. }
  3058. *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;
  3059. break;
  3060. case KEY_SAVE_ORDER_CHANGES:
  3061. //
  3062. // Sync the Attempt Order to NVR.
  3063. //
  3064. Status = IScsiConfigOrderAttempts (IfrNvData);
  3065. if (EFI_ERROR (Status)) {
  3066. break;
  3067. }
  3068. IScsiConfigUpdateAttempt ();
  3069. *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;
  3070. break;
  3071. case KEY_IGNORE_ORDER_CHANGES:
  3072. CopyMem (
  3073. IfrNvData->DynamicOrderedList,
  3074. OldIfrNvData.DynamicOrderedList,
  3075. sizeof (IfrNvData->DynamicOrderedList)
  3076. );
  3077. *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;
  3078. break;
  3079. case KEY_SAVE_DELETE_ATTEMPT:
  3080. //
  3081. // Delete the Attempt Order from NVR
  3082. //
  3083. Status = IScsiConfigDeleteAttempts (IfrNvData);
  3084. if (EFI_ERROR (Status)) {
  3085. break;
  3086. }
  3087. IScsiConfigUpdateAttempt ();
  3088. *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;
  3089. break;
  3090. case KEY_IGNORE_DELETE_ATTEMPT:
  3091. CopyMem (
  3092. IfrNvData->DeleteAttemptList,
  3093. OldIfrNvData.DeleteAttemptList,
  3094. sizeof (IfrNvData->DeleteAttemptList)
  3095. );
  3096. *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;
  3097. break;
  3098. case KEY_IP_MODE:
  3099. switch (Value->u8) {
  3100. case IP_MODE_IP6:
  3101. NicInfo = IScsiGetNicInfoByIndex (Private->Current->NicIndex);
  3102. if(NicInfo == NULL) {
  3103. break;
  3104. }
  3105. if(!NicInfo->Ipv6Available) {
  3106. //
  3107. // Current NIC doesn't Support IPv6, hence use IPv4.
  3108. //
  3109. IfrNvData->IpMode = IP_MODE_IP4;
  3110. CreatePopUp (
  3111. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  3112. &Key,
  3113. L"Current NIC doesn't Support IPv6!",
  3114. NULL
  3115. );
  3116. }
  3117. case IP_MODE_IP4:
  3118. ZeroMem (IfrNvData->LocalIp, sizeof (IfrNvData->LocalIp));
  3119. ZeroMem (IfrNvData->SubnetMask, sizeof (IfrNvData->SubnetMask));
  3120. ZeroMem (IfrNvData->Gateway, sizeof (IfrNvData->Gateway));
  3121. ZeroMem (IfrNvData->TargetIp, sizeof (IfrNvData->TargetIp));
  3122. Private->Current->AutoConfigureMode = 0;
  3123. ZeroMem (&Private->Current->SessionConfigData.LocalIp, sizeof (EFI_IP_ADDRESS));
  3124. ZeroMem (&Private->Current->SessionConfigData.SubnetMask, sizeof (EFI_IPv4_ADDRESS));
  3125. ZeroMem (&Private->Current->SessionConfigData.Gateway, sizeof (EFI_IP_ADDRESS));
  3126. ZeroMem (&Private->Current->SessionConfigData.TargetIp, sizeof (EFI_IP_ADDRESS));
  3127. break;
  3128. }
  3129. break;
  3130. case KEY_LOCAL_IP:
  3131. Status = NetLibStrToIp4 (IfrNvData->LocalIp, &HostIp.v4);
  3132. if (EFI_ERROR (Status) ||
  3133. ((Private->Current->SessionConfigData.SubnetMask.Addr[0] != 0) &&
  3134. !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), NTOHL(*(UINT32*)Private->Current->SessionConfigData.SubnetMask.Addr)))) {
  3135. CreatePopUp (
  3136. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  3137. &Key,
  3138. L"Invalid IP address!",
  3139. NULL
  3140. );
  3141. Status = EFI_INVALID_PARAMETER;
  3142. } else {
  3143. CopyMem (&Private->Current->SessionConfigData.LocalIp, &HostIp.v4, sizeof (HostIp.v4));
  3144. }
  3145. break;
  3146. case KEY_SUBNET_MASK:
  3147. Status = NetLibStrToIp4 (IfrNvData->SubnetMask, &SubnetMask.v4);
  3148. if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] != 0) && (IScsiGetSubnetMaskPrefixLength (&SubnetMask.v4) == 0))) {
  3149. CreatePopUp (
  3150. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  3151. &Key,
  3152. L"Invalid Subnet Mask!",
  3153. NULL
  3154. );
  3155. Status = EFI_INVALID_PARAMETER;
  3156. } else {
  3157. CopyMem (&Private->Current->SessionConfigData.SubnetMask, &SubnetMask.v4, sizeof (SubnetMask.v4));
  3158. }
  3159. break;
  3160. case KEY_GATE_WAY:
  3161. Status = NetLibStrToIp4 (IfrNvData->Gateway, &Gateway.v4);
  3162. if (EFI_ERROR (Status) ||
  3163. ((Gateway.Addr[0] != 0) &&
  3164. (Private->Current->SessionConfigData.SubnetMask.Addr[0] != 0) &&
  3165. !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), NTOHL(*(UINT32*)Private->Current->SessionConfigData.SubnetMask.Addr)))) {
  3166. CreatePopUp (
  3167. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  3168. &Key,
  3169. L"Invalid Gateway!",
  3170. NULL
  3171. );
  3172. Status = EFI_INVALID_PARAMETER;
  3173. } else {
  3174. CopyMem (&Private->Current->SessionConfigData.Gateway, &Gateway.v4, sizeof (Gateway.v4));
  3175. }
  3176. break;
  3177. case KEY_TARGET_IP:
  3178. UnicodeStrToAsciiStrS (IfrNvData->TargetIp, IpString, sizeof (IpString));
  3179. Status = IScsiAsciiStrToIp (IpString, IfrNvData->IpMode, &HostIp);
  3180. if (EFI_ERROR (Status) || !IpIsUnicast (&HostIp, IfrNvData->IpMode)) {
  3181. //
  3182. // The target is expressed in URL format or an invalid Ip address, just save.
  3183. //
  3184. Private->Current->SessionConfigData.DnsMode = TRUE;
  3185. ZeroMem (&Private->Current->SessionConfigData.TargetIp, sizeof (Private->Current->SessionConfigData.TargetIp));
  3186. UnicodeStrToAsciiStrS (IfrNvData->TargetIp, Private->Current->SessionConfigData.TargetUrl, ISCSI_NAME_MAX_SIZE);
  3187. } else {
  3188. Private->Current->SessionConfigData.DnsMode = FALSE;
  3189. CopyMem (&Private->Current->SessionConfigData.TargetIp, &HostIp, sizeof (HostIp));
  3190. }
  3191. break;
  3192. case KEY_TARGET_NAME:
  3193. UnicodeStrToAsciiStrS (IfrNvData->TargetName, IScsiName, ISCSI_NAME_MAX_SIZE);
  3194. Status = IScsiNormalizeName (IScsiName, AsciiStrLen (IScsiName));
  3195. if (EFI_ERROR (Status)) {
  3196. CreatePopUp (
  3197. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  3198. &Key,
  3199. L"Invalid iSCSI Name!",
  3200. NULL
  3201. );
  3202. } else {
  3203. AsciiStrCpyS (Private->Current->SessionConfigData.TargetName, ISCSI_NAME_MAX_SIZE, IScsiName);
  3204. }
  3205. break;
  3206. case KEY_DHCP_ENABLE:
  3207. if (IfrNvData->InitiatorInfoFromDhcp == 0) {
  3208. IfrNvData->TargetInfoFromDhcp = 0;
  3209. }
  3210. break;
  3211. case KEY_BOOT_LUN:
  3212. UnicodeStrToAsciiStrS (IfrNvData->BootLun, LunString, sizeof (LunString));
  3213. Status = IScsiAsciiStrToLun (LunString, (UINT8 *) &Lun);
  3214. if (EFI_ERROR (Status)) {
  3215. CreatePopUp (
  3216. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  3217. &Key,
  3218. L"Invalid LUN string!",
  3219. NULL
  3220. );
  3221. } else {
  3222. CopyMem (Private->Current->SessionConfigData.BootLun, &Lun, sizeof (Lun));
  3223. }
  3224. break;
  3225. case KEY_AUTH_TYPE:
  3226. switch (Value->u8) {
  3227. case ISCSI_AUTH_TYPE_CHAP:
  3228. IfrNvData->CHAPType = ISCSI_CHAP_UNI;
  3229. break;
  3230. default:
  3231. break;
  3232. }
  3233. break;
  3234. case KEY_CHAP_NAME:
  3235. UnicodeStrToAsciiStrS (
  3236. IfrNvData->CHAPName,
  3237. Private->Current->AuthConfigData.CHAP.CHAPName,
  3238. sizeof (Private->Current->AuthConfigData.CHAP.CHAPName)
  3239. );
  3240. break;
  3241. case KEY_CHAP_SECRET:
  3242. UnicodeStrToAsciiStrS (
  3243. IfrNvData->CHAPSecret,
  3244. Private->Current->AuthConfigData.CHAP.CHAPSecret,
  3245. sizeof (Private->Current->AuthConfigData.CHAP.CHAPSecret)
  3246. );
  3247. break;
  3248. case KEY_REVERSE_CHAP_NAME:
  3249. UnicodeStrToAsciiStrS (
  3250. IfrNvData->ReverseCHAPName,
  3251. Private->Current->AuthConfigData.CHAP.ReverseCHAPName,
  3252. sizeof (Private->Current->AuthConfigData.CHAP.ReverseCHAPName)
  3253. );
  3254. break;
  3255. case KEY_REVERSE_CHAP_SECRET:
  3256. UnicodeStrToAsciiStrS (
  3257. IfrNvData->ReverseCHAPSecret,
  3258. Private->Current->AuthConfigData.CHAP.ReverseCHAPSecret,
  3259. sizeof (Private->Current->AuthConfigData.CHAP.ReverseCHAPSecret)
  3260. );
  3261. break;
  3262. case KEY_CONFIG_ISID:
  3263. IScsiParseIsIdFromString (IfrNvData->IsId, Private->Current->SessionConfigData.IsId);
  3264. IScsiConvertIsIdToString (IfrNvData->IsId, Private->Current->SessionConfigData.IsId);
  3265. break;
  3266. default:
  3267. break;
  3268. }
  3269. }
  3270. if (!EFI_ERROR (Status)) {
  3271. //
  3272. // Pass changed uncommitted data back to Form Browser.
  3273. //
  3274. BufferSize = sizeof (ISCSI_CONFIG_IFR_NVDATA);
  3275. HiiSetBrowserData (NULL, NULL, BufferSize, (UINT8 *) IfrNvData, NULL);
  3276. }
  3277. FreePool (IfrNvData);
  3278. FreePool (IScsiName);
  3279. return Status;
  3280. }
  3281. /**
  3282. Initialize the iSCSI configuration form.
  3283. @param[in] DriverBindingHandle The iSCSI driverbinding handle.
  3284. @retval EFI_SUCCESS The iSCSI configuration form is initialized.
  3285. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
  3286. **/
  3287. EFI_STATUS
  3288. IScsiConfigFormInit (
  3289. IN EFI_HANDLE DriverBindingHandle
  3290. )
  3291. {
  3292. EFI_STATUS Status;
  3293. ISCSI_FORM_CALLBACK_INFO *CallbackInfo;
  3294. CallbackInfo = (ISCSI_FORM_CALLBACK_INFO *) AllocateZeroPool (sizeof (ISCSI_FORM_CALLBACK_INFO));
  3295. if (CallbackInfo == NULL) {
  3296. return EFI_OUT_OF_RESOURCES;
  3297. }
  3298. CallbackInfo->Signature = ISCSI_FORM_CALLBACK_INFO_SIGNATURE;
  3299. CallbackInfo->Current = NULL;
  3300. CallbackInfo->ConfigAccess.ExtractConfig = IScsiFormExtractConfig;
  3301. CallbackInfo->ConfigAccess.RouteConfig = IScsiFormRouteConfig;
  3302. CallbackInfo->ConfigAccess.Callback = IScsiFormCallback;
  3303. //
  3304. // Install Device Path Protocol and Config Access protocol to driver handle.
  3305. //
  3306. Status = gBS->InstallMultipleProtocolInterfaces (
  3307. &CallbackInfo->DriverHandle,
  3308. &gEfiDevicePathProtocolGuid,
  3309. &mIScsiHiiVendorDevicePath,
  3310. &gEfiHiiConfigAccessProtocolGuid,
  3311. &CallbackInfo->ConfigAccess,
  3312. NULL
  3313. );
  3314. ASSERT_EFI_ERROR (Status);
  3315. //
  3316. // Publish our HII data.
  3317. //
  3318. CallbackInfo->RegisteredHandle = HiiAddPackages (
  3319. &gIScsiConfigGuid,
  3320. CallbackInfo->DriverHandle,
  3321. IScsiDxeStrings,
  3322. IScsiConfigVfrBin,
  3323. NULL
  3324. );
  3325. if (CallbackInfo->RegisteredHandle == NULL) {
  3326. gBS->UninstallMultipleProtocolInterfaces (
  3327. &CallbackInfo->DriverHandle,
  3328. &gEfiDevicePathProtocolGuid,
  3329. &mIScsiHiiVendorDevicePath,
  3330. &gEfiHiiConfigAccessProtocolGuid,
  3331. &CallbackInfo->ConfigAccess,
  3332. NULL
  3333. );
  3334. FreePool(CallbackInfo);
  3335. return EFI_OUT_OF_RESOURCES;
  3336. }
  3337. mCallbackInfo = CallbackInfo;
  3338. return EFI_SUCCESS;
  3339. }
  3340. /**
  3341. Unload the iSCSI configuration form, this includes: delete all the iSCSI
  3342. configuration entries, uninstall the form callback protocol, and
  3343. free the resources used.
  3344. @param[in] DriverBindingHandle The iSCSI driverbinding handle.
  3345. @retval EFI_SUCCESS The iSCSI configuration form is unloaded.
  3346. @retval Others Failed to unload the form.
  3347. **/
  3348. EFI_STATUS
  3349. IScsiConfigFormUnload (
  3350. IN EFI_HANDLE DriverBindingHandle
  3351. )
  3352. {
  3353. ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;
  3354. ISCSI_NIC_INFO *NicInfo;
  3355. LIST_ENTRY *Entry;
  3356. EFI_STATUS Status;
  3357. while (!IsListEmpty (&mPrivate->AttemptConfigs)) {
  3358. Entry = NetListRemoveHead (&mPrivate->AttemptConfigs);
  3359. AttemptConfigData = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
  3360. FreePool (AttemptConfigData);
  3361. mPrivate->AttemptCount--;
  3362. }
  3363. ASSERT (mPrivate->AttemptCount == 0);
  3364. while (!IsListEmpty (&mPrivate->NicInfoList)) {
  3365. Entry = NetListRemoveHead (&mPrivate->NicInfoList);
  3366. NicInfo = NET_LIST_USER_STRUCT (Entry, ISCSI_NIC_INFO, Link);
  3367. FreePool (NicInfo);
  3368. mPrivate->NicCount--;
  3369. }
  3370. ASSERT (mPrivate->NicCount == 0);
  3371. FreePool (mPrivate);
  3372. mPrivate = NULL;
  3373. //
  3374. // Remove HII package list.
  3375. //
  3376. HiiRemovePackages (mCallbackInfo->RegisteredHandle);
  3377. //
  3378. // Uninstall Device Path Protocol and Config Access protocol.
  3379. //
  3380. Status = gBS->UninstallMultipleProtocolInterfaces (
  3381. mCallbackInfo->DriverHandle,
  3382. &gEfiDevicePathProtocolGuid,
  3383. &mIScsiHiiVendorDevicePath,
  3384. &gEfiHiiConfigAccessProtocolGuid,
  3385. &mCallbackInfo->ConfigAccess,
  3386. NULL
  3387. );
  3388. FreePool (mCallbackInfo);
  3389. return Status;
  3390. }