DevicePathFromText.c 107 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520
  1. /** @file
  2. DevicePathFromText protocol as defined in the UEFI 2.0 specification.
  3. Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "UefiDevicePathLib.h"
  7. /**
  8. Duplicates a string.
  9. @param Src Source string.
  10. @return The duplicated string.
  11. **/
  12. CHAR16 *
  13. UefiDevicePathLibStrDuplicate (
  14. CONST CHAR16 *Src
  15. )
  16. {
  17. return AllocateCopyPool (StrSize (Src), Src);
  18. }
  19. /**
  20. Get parameter in a pair of parentheses follow the given node name.
  21. For example, given the "Pci(0,1)" and NodeName "Pci", it returns "0,1".
  22. @param Str Device Path Text.
  23. @param NodeName Name of the node.
  24. @return Parameter text for the node.
  25. **/
  26. CHAR16 *
  27. GetParamByNodeName (
  28. CHAR16 *Str,
  29. CHAR16 *NodeName
  30. )
  31. {
  32. CHAR16 *ParamStr;
  33. CHAR16 *StrPointer;
  34. UINTN NodeNameLength;
  35. UINTN ParameterLength;
  36. //
  37. // Check whether the node name matchs
  38. //
  39. NodeNameLength = StrLen (NodeName);
  40. if (StrnCmp (Str, NodeName, NodeNameLength) != 0) {
  41. return NULL;
  42. }
  43. ParamStr = Str + NodeNameLength;
  44. if (!IS_LEFT_PARENTH (*ParamStr)) {
  45. return NULL;
  46. }
  47. //
  48. // Skip the found '(' and find first occurrence of ')'
  49. //
  50. ParamStr++;
  51. ParameterLength = 0;
  52. StrPointer = ParamStr;
  53. while (!IS_NULL (*StrPointer)) {
  54. if (IS_RIGHT_PARENTH (*StrPointer)) {
  55. break;
  56. }
  57. StrPointer++;
  58. ParameterLength++;
  59. }
  60. if (IS_NULL (*StrPointer)) {
  61. //
  62. // ')' not found
  63. //
  64. return NULL;
  65. }
  66. ParamStr = AllocateCopyPool ((ParameterLength + 1) * sizeof (CHAR16), ParamStr);
  67. if (ParamStr == NULL) {
  68. return NULL;
  69. }
  70. //
  71. // Terminate the parameter string
  72. //
  73. ParamStr[ParameterLength] = L'\0';
  74. return ParamStr;
  75. }
  76. /**
  77. Gets the next parameter string from the list.
  78. @param List A string list separated by the specified separator
  79. @return A pointer to the current sub-string
  80. **/
  81. CHAR16 *
  82. GetNextParamStr (
  83. CHAR16 **List
  84. )
  85. {
  86. //
  87. // The separator is comma
  88. //
  89. return SplitStr (List, L',');
  90. }
  91. /**
  92. Get one device node from entire device path text.
  93. @param DevicePath On input, the current Device Path node; on output, the next device path node
  94. @param IsInstanceEnd This node is the end of a device path instance
  95. @return A device node text or NULL if no more device node available
  96. **/
  97. CHAR16 *
  98. GetNextDeviceNodeStr (
  99. CHAR16 **DevicePath,
  100. BOOLEAN *IsInstanceEnd
  101. )
  102. {
  103. CHAR16 *Str;
  104. CHAR16 *ReturnStr;
  105. UINTN ParenthesesStack;
  106. Str = *DevicePath;
  107. if (IS_NULL (*Str)) {
  108. return NULL;
  109. }
  110. //
  111. // Skip the leading '/', '(', ')' and ','
  112. //
  113. while (!IS_NULL (*Str)) {
  114. if (!IS_SLASH (*Str) &&
  115. !IS_COMMA (*Str) &&
  116. !IS_LEFT_PARENTH (*Str) &&
  117. !IS_RIGHT_PARENTH (*Str)) {
  118. break;
  119. }
  120. Str++;
  121. }
  122. ReturnStr = Str;
  123. //
  124. // Scan for the separator of this device node, '/' or ','
  125. //
  126. ParenthesesStack = 0;
  127. while (!IS_NULL (*Str)) {
  128. if ((IS_COMMA (*Str) || IS_SLASH (*Str)) && (ParenthesesStack == 0)) {
  129. break;
  130. }
  131. if (IS_LEFT_PARENTH (*Str)) {
  132. ParenthesesStack++;
  133. } else if (IS_RIGHT_PARENTH (*Str)) {
  134. ParenthesesStack--;
  135. }
  136. Str++;
  137. }
  138. if (ParenthesesStack != 0) {
  139. //
  140. // The '(' doesn't pair with ')', invalid device path text
  141. //
  142. return NULL;
  143. }
  144. if (IS_COMMA (*Str)) {
  145. *IsInstanceEnd = TRUE;
  146. *Str = L'\0';
  147. Str++;
  148. } else {
  149. *IsInstanceEnd = FALSE;
  150. if (!IS_NULL (*Str)) {
  151. *Str = L'\0';
  152. Str++;
  153. }
  154. }
  155. *DevicePath = Str;
  156. return ReturnStr;
  157. }
  158. /**
  159. Converts a generic text device path node to device path structure.
  160. @param Type The type of the device path node.
  161. @param TextDeviceNode The input text device path node.
  162. @return A pointer to device path structure.
  163. **/
  164. EFI_DEVICE_PATH_PROTOCOL *
  165. DevPathFromTextGenericPath (
  166. UINT8 Type,
  167. CHAR16 *TextDeviceNode
  168. )
  169. {
  170. EFI_DEVICE_PATH_PROTOCOL *Node;
  171. CHAR16 *SubtypeStr;
  172. CHAR16 *DataStr;
  173. UINTN DataLength;
  174. SubtypeStr = GetNextParamStr (&TextDeviceNode);
  175. DataStr = GetNextParamStr (&TextDeviceNode);
  176. if (DataStr == NULL) {
  177. DataLength = 0;
  178. } else {
  179. DataLength = StrLen (DataStr) / 2;
  180. }
  181. Node = CreateDeviceNode (
  182. Type,
  183. (UINT8) Strtoi (SubtypeStr),
  184. (UINT16) (sizeof (EFI_DEVICE_PATH_PROTOCOL) + DataLength)
  185. );
  186. StrHexToBytes (DataStr, DataLength * 2, (UINT8 *) (Node + 1), DataLength);
  187. return Node;
  188. }
  189. /**
  190. Converts a generic text device path node to device path structure.
  191. @param TextDeviceNode The input Text device path node.
  192. @return A pointer to device path structure.
  193. **/
  194. EFI_DEVICE_PATH_PROTOCOL *
  195. DevPathFromTextPath (
  196. CHAR16 *TextDeviceNode
  197. )
  198. {
  199. CHAR16 *TypeStr;
  200. TypeStr = GetNextParamStr (&TextDeviceNode);
  201. return DevPathFromTextGenericPath ((UINT8) Strtoi (TypeStr), TextDeviceNode);
  202. }
  203. /**
  204. Converts a generic hardware text device path node to Hardware device path structure.
  205. @param TextDeviceNode The input Text device path node.
  206. @return A pointer to Hardware device path structure.
  207. **/
  208. EFI_DEVICE_PATH_PROTOCOL *
  209. DevPathFromTextHardwarePath (
  210. CHAR16 *TextDeviceNode
  211. )
  212. {
  213. return DevPathFromTextGenericPath (HARDWARE_DEVICE_PATH, TextDeviceNode);
  214. }
  215. /**
  216. Converts a text device path node to Hardware PCI device path structure.
  217. @param TextDeviceNode The input Text device path node.
  218. @return A pointer to Hardware PCI device path structure.
  219. **/
  220. EFI_DEVICE_PATH_PROTOCOL *
  221. DevPathFromTextPci (
  222. CHAR16 *TextDeviceNode
  223. )
  224. {
  225. CHAR16 *FunctionStr;
  226. CHAR16 *DeviceStr;
  227. PCI_DEVICE_PATH *Pci;
  228. DeviceStr = GetNextParamStr (&TextDeviceNode);
  229. FunctionStr = GetNextParamStr (&TextDeviceNode);
  230. Pci = (PCI_DEVICE_PATH *) CreateDeviceNode (
  231. HARDWARE_DEVICE_PATH,
  232. HW_PCI_DP,
  233. (UINT16) sizeof (PCI_DEVICE_PATH)
  234. );
  235. Pci->Function = (UINT8) Strtoi (FunctionStr);
  236. Pci->Device = (UINT8) Strtoi (DeviceStr);
  237. return (EFI_DEVICE_PATH_PROTOCOL *) Pci;
  238. }
  239. /**
  240. Converts a text device path node to Hardware PC card device path structure.
  241. @param TextDeviceNode The input Text device path node.
  242. @return A pointer to Hardware PC card device path structure.
  243. **/
  244. EFI_DEVICE_PATH_PROTOCOL *
  245. DevPathFromTextPcCard (
  246. CHAR16 *TextDeviceNode
  247. )
  248. {
  249. CHAR16 *FunctionNumberStr;
  250. PCCARD_DEVICE_PATH *Pccard;
  251. FunctionNumberStr = GetNextParamStr (&TextDeviceNode);
  252. Pccard = (PCCARD_DEVICE_PATH *) CreateDeviceNode (
  253. HARDWARE_DEVICE_PATH,
  254. HW_PCCARD_DP,
  255. (UINT16) sizeof (PCCARD_DEVICE_PATH)
  256. );
  257. Pccard->FunctionNumber = (UINT8) Strtoi (FunctionNumberStr);
  258. return (EFI_DEVICE_PATH_PROTOCOL *) Pccard;
  259. }
  260. /**
  261. Converts a text device path node to Hardware memory map device path structure.
  262. @param TextDeviceNode The input Text device path node.
  263. @return A pointer to Hardware memory map device path structure.
  264. **/
  265. EFI_DEVICE_PATH_PROTOCOL *
  266. DevPathFromTextMemoryMapped (
  267. CHAR16 *TextDeviceNode
  268. )
  269. {
  270. CHAR16 *MemoryTypeStr;
  271. CHAR16 *StartingAddressStr;
  272. CHAR16 *EndingAddressStr;
  273. MEMMAP_DEVICE_PATH *MemMap;
  274. MemoryTypeStr = GetNextParamStr (&TextDeviceNode);
  275. StartingAddressStr = GetNextParamStr (&TextDeviceNode);
  276. EndingAddressStr = GetNextParamStr (&TextDeviceNode);
  277. MemMap = (MEMMAP_DEVICE_PATH *) CreateDeviceNode (
  278. HARDWARE_DEVICE_PATH,
  279. HW_MEMMAP_DP,
  280. (UINT16) sizeof (MEMMAP_DEVICE_PATH)
  281. );
  282. MemMap->MemoryType = (UINT32) Strtoi (MemoryTypeStr);
  283. Strtoi64 (StartingAddressStr, &MemMap->StartingAddress);
  284. Strtoi64 (EndingAddressStr, &MemMap->EndingAddress);
  285. return (EFI_DEVICE_PATH_PROTOCOL *) MemMap;
  286. }
  287. /**
  288. Converts a text device path node to Vendor device path structure based on the input Type
  289. and SubType.
  290. @param TextDeviceNode The input Text device path node.
  291. @param Type The type of device path node.
  292. @param SubType The subtype of device path node.
  293. @return A pointer to the newly-created Vendor device path structure.
  294. **/
  295. EFI_DEVICE_PATH_PROTOCOL *
  296. ConvertFromTextVendor (
  297. CHAR16 *TextDeviceNode,
  298. UINT8 Type,
  299. UINT8 SubType
  300. )
  301. {
  302. CHAR16 *GuidStr;
  303. CHAR16 *DataStr;
  304. UINTN Length;
  305. VENDOR_DEVICE_PATH *Vendor;
  306. GuidStr = GetNextParamStr (&TextDeviceNode);
  307. DataStr = GetNextParamStr (&TextDeviceNode);
  308. Length = StrLen (DataStr);
  309. //
  310. // Two hex characters make up 1 buffer byte
  311. //
  312. Length = (Length + 1) / 2;
  313. Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
  314. Type,
  315. SubType,
  316. (UINT16) (sizeof (VENDOR_DEVICE_PATH) + Length)
  317. );
  318. StrToGuid (GuidStr, &Vendor->Guid);
  319. StrHexToBytes (DataStr, Length * 2, (UINT8 *) (Vendor + 1), Length);
  320. return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
  321. }
  322. /**
  323. Converts a text device path node to Vendor Hardware device path structure.
  324. @param TextDeviceNode The input Text device path node.
  325. @return A pointer to the newly-created Vendor Hardware device path structure.
  326. **/
  327. EFI_DEVICE_PATH_PROTOCOL *
  328. DevPathFromTextVenHw (
  329. CHAR16 *TextDeviceNode
  330. )
  331. {
  332. return ConvertFromTextVendor (
  333. TextDeviceNode,
  334. HARDWARE_DEVICE_PATH,
  335. HW_VENDOR_DP
  336. );
  337. }
  338. /**
  339. Converts a text device path node to Hardware Controller device path structure.
  340. @param TextDeviceNode The input Text device path node.
  341. @return A pointer to the newly-created Hardware Controller device path structure.
  342. **/
  343. EFI_DEVICE_PATH_PROTOCOL *
  344. DevPathFromTextCtrl (
  345. CHAR16 *TextDeviceNode
  346. )
  347. {
  348. CHAR16 *ControllerStr;
  349. CONTROLLER_DEVICE_PATH *Controller;
  350. ControllerStr = GetNextParamStr (&TextDeviceNode);
  351. Controller = (CONTROLLER_DEVICE_PATH *) CreateDeviceNode (
  352. HARDWARE_DEVICE_PATH,
  353. HW_CONTROLLER_DP,
  354. (UINT16) sizeof (CONTROLLER_DEVICE_PATH)
  355. );
  356. Controller->ControllerNumber = (UINT32) Strtoi (ControllerStr);
  357. return (EFI_DEVICE_PATH_PROTOCOL *) Controller;
  358. }
  359. /**
  360. Converts a text device path node to BMC device path structure.
  361. @param TextDeviceNode The input Text device path node.
  362. @return A pointer to the newly-created BMC device path structure.
  363. **/
  364. EFI_DEVICE_PATH_PROTOCOL *
  365. DevPathFromTextBmc (
  366. CHAR16 *TextDeviceNode
  367. )
  368. {
  369. CHAR16 *InterfaceTypeStr;
  370. CHAR16 *BaseAddressStr;
  371. BMC_DEVICE_PATH *BmcDp;
  372. InterfaceTypeStr = GetNextParamStr (&TextDeviceNode);
  373. BaseAddressStr = GetNextParamStr (&TextDeviceNode);
  374. BmcDp = (BMC_DEVICE_PATH *) CreateDeviceNode (
  375. HARDWARE_DEVICE_PATH,
  376. HW_BMC_DP,
  377. (UINT16) sizeof (BMC_DEVICE_PATH)
  378. );
  379. BmcDp->InterfaceType = (UINT8) Strtoi (InterfaceTypeStr);
  380. WriteUnaligned64 (
  381. (UINT64 *) (&BmcDp->BaseAddress),
  382. StrHexToUint64 (BaseAddressStr)
  383. );
  384. return (EFI_DEVICE_PATH_PROTOCOL *) BmcDp;
  385. }
  386. /**
  387. Converts a generic ACPI text device path node to ACPI device path structure.
  388. @param TextDeviceNode The input Text device path node.
  389. @return A pointer to ACPI device path structure.
  390. **/
  391. EFI_DEVICE_PATH_PROTOCOL *
  392. DevPathFromTextAcpiPath (
  393. CHAR16 *TextDeviceNode
  394. )
  395. {
  396. return DevPathFromTextGenericPath (ACPI_DEVICE_PATH, TextDeviceNode);
  397. }
  398. /**
  399. Converts a string to EisaId.
  400. @param Text The input string.
  401. @return UINT32 EISA ID.
  402. **/
  403. UINT32
  404. EisaIdFromText (
  405. CHAR16 *Text
  406. )
  407. {
  408. return (((Text[0] - 'A' + 1) & 0x1f) << 10)
  409. + (((Text[1] - 'A' + 1) & 0x1f) << 5)
  410. + (((Text[2] - 'A' + 1) & 0x1f) << 0)
  411. + (UINT32) (StrHexToUint64 (&Text[3]) << 16)
  412. ;
  413. }
  414. /**
  415. Converts a text device path node to ACPI HID device path structure.
  416. @param TextDeviceNode The input Text device path node.
  417. @return A pointer to the newly-created ACPI HID device path structure.
  418. **/
  419. EFI_DEVICE_PATH_PROTOCOL *
  420. DevPathFromTextAcpi (
  421. CHAR16 *TextDeviceNode
  422. )
  423. {
  424. CHAR16 *HIDStr;
  425. CHAR16 *UIDStr;
  426. ACPI_HID_DEVICE_PATH *Acpi;
  427. HIDStr = GetNextParamStr (&TextDeviceNode);
  428. UIDStr = GetNextParamStr (&TextDeviceNode);
  429. Acpi = (ACPI_HID_DEVICE_PATH *) CreateDeviceNode (
  430. ACPI_DEVICE_PATH,
  431. ACPI_DP,
  432. (UINT16) sizeof (ACPI_HID_DEVICE_PATH)
  433. );
  434. Acpi->HID = EisaIdFromText (HIDStr);
  435. Acpi->UID = (UINT32) Strtoi (UIDStr);
  436. return (EFI_DEVICE_PATH_PROTOCOL *) Acpi;
  437. }
  438. /**
  439. Converts a text device path node to ACPI HID device path structure.
  440. @param TextDeviceNode The input Text device path node.
  441. @param PnPId The input plug and play identification.
  442. @return A pointer to the newly-created ACPI HID device path structure.
  443. **/
  444. EFI_DEVICE_PATH_PROTOCOL *
  445. ConvertFromTextAcpi (
  446. CHAR16 *TextDeviceNode,
  447. UINT32 PnPId
  448. )
  449. {
  450. CHAR16 *UIDStr;
  451. ACPI_HID_DEVICE_PATH *Acpi;
  452. UIDStr = GetNextParamStr (&TextDeviceNode);
  453. Acpi = (ACPI_HID_DEVICE_PATH *) CreateDeviceNode (
  454. ACPI_DEVICE_PATH,
  455. ACPI_DP,
  456. (UINT16) sizeof (ACPI_HID_DEVICE_PATH)
  457. );
  458. Acpi->HID = EFI_PNP_ID (PnPId);
  459. Acpi->UID = (UINT32) Strtoi (UIDStr);
  460. return (EFI_DEVICE_PATH_PROTOCOL *) Acpi;
  461. }
  462. /**
  463. Converts a text device path node to PCI root device path structure.
  464. @param TextDeviceNode The input Text device path node.
  465. @return A pointer to the newly-created PCI root device path structure.
  466. **/
  467. EFI_DEVICE_PATH_PROTOCOL *
  468. DevPathFromTextPciRoot (
  469. CHAR16 *TextDeviceNode
  470. )
  471. {
  472. return ConvertFromTextAcpi (TextDeviceNode, 0x0a03);
  473. }
  474. /**
  475. Converts a text device path node to PCIE root device path structure.
  476. @param TextDeviceNode The input Text device path node.
  477. @return A pointer to the newly-created PCIE root device path structure.
  478. **/
  479. EFI_DEVICE_PATH_PROTOCOL *
  480. DevPathFromTextPcieRoot (
  481. CHAR16 *TextDeviceNode
  482. )
  483. {
  484. return ConvertFromTextAcpi (TextDeviceNode, 0x0a08);
  485. }
  486. /**
  487. Converts a text device path node to Floppy device path structure.
  488. @param TextDeviceNode The input Text device path node.
  489. @return A pointer to the newly-created Floppy device path structure.
  490. **/
  491. EFI_DEVICE_PATH_PROTOCOL *
  492. DevPathFromTextFloppy (
  493. CHAR16 *TextDeviceNode
  494. )
  495. {
  496. return ConvertFromTextAcpi (TextDeviceNode, 0x0604);
  497. }
  498. /**
  499. Converts a text device path node to Keyboard device path structure.
  500. @param TextDeviceNode The input Text device path node.
  501. @return A pointer to the newly-created Keyboard device path structure.
  502. **/
  503. EFI_DEVICE_PATH_PROTOCOL *
  504. DevPathFromTextKeyboard (
  505. CHAR16 *TextDeviceNode
  506. )
  507. {
  508. return ConvertFromTextAcpi (TextDeviceNode, 0x0301);
  509. }
  510. /**
  511. Converts a text device path node to Serial device path structure.
  512. @param TextDeviceNode The input Text device path node.
  513. @return A pointer to the newly-created Serial device path structure.
  514. **/
  515. EFI_DEVICE_PATH_PROTOCOL *
  516. DevPathFromTextSerial (
  517. CHAR16 *TextDeviceNode
  518. )
  519. {
  520. return ConvertFromTextAcpi (TextDeviceNode, 0x0501);
  521. }
  522. /**
  523. Converts a text device path node to Parallel Port device path structure.
  524. @param TextDeviceNode The input Text device path node.
  525. @return A pointer to the newly-created Parallel Port device path structure.
  526. **/
  527. EFI_DEVICE_PATH_PROTOCOL *
  528. DevPathFromTextParallelPort (
  529. CHAR16 *TextDeviceNode
  530. )
  531. {
  532. return ConvertFromTextAcpi (TextDeviceNode, 0x0401);
  533. }
  534. /**
  535. Converts a text device path node to ACPI extension device path structure.
  536. @param TextDeviceNode The input Text device path node.
  537. @return A pointer to the newly-created ACPI extension device path structure.
  538. **/
  539. EFI_DEVICE_PATH_PROTOCOL *
  540. DevPathFromTextAcpiEx (
  541. CHAR16 *TextDeviceNode
  542. )
  543. {
  544. CHAR16 *HIDStr;
  545. CHAR16 *CIDStr;
  546. CHAR16 *UIDStr;
  547. CHAR16 *HIDSTRStr;
  548. CHAR16 *CIDSTRStr;
  549. CHAR16 *UIDSTRStr;
  550. CHAR8 *AsciiStr;
  551. UINT16 Length;
  552. ACPI_EXTENDED_HID_DEVICE_PATH *AcpiEx;
  553. HIDStr = GetNextParamStr (&TextDeviceNode);
  554. CIDStr = GetNextParamStr (&TextDeviceNode);
  555. UIDStr = GetNextParamStr (&TextDeviceNode);
  556. HIDSTRStr = GetNextParamStr (&TextDeviceNode);
  557. CIDSTRStr = GetNextParamStr (&TextDeviceNode);
  558. UIDSTRStr = GetNextParamStr (&TextDeviceNode);
  559. Length = (UINT16) (sizeof (ACPI_EXTENDED_HID_DEVICE_PATH) + StrLen (HIDSTRStr) + 1);
  560. Length = (UINT16) (Length + StrLen (UIDSTRStr) + 1);
  561. Length = (UINT16) (Length + StrLen (CIDSTRStr) + 1);
  562. AcpiEx = (ACPI_EXTENDED_HID_DEVICE_PATH *) CreateDeviceNode (
  563. ACPI_DEVICE_PATH,
  564. ACPI_EXTENDED_DP,
  565. Length
  566. );
  567. AcpiEx->HID = EisaIdFromText (HIDStr);
  568. AcpiEx->CID = EisaIdFromText (CIDStr);
  569. AcpiEx->UID = (UINT32) Strtoi (UIDStr);
  570. AsciiStr = (CHAR8 *) ((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
  571. StrToAscii (HIDSTRStr, &AsciiStr);
  572. StrToAscii (UIDSTRStr, &AsciiStr);
  573. StrToAscii (CIDSTRStr, &AsciiStr);
  574. return (EFI_DEVICE_PATH_PROTOCOL *) AcpiEx;
  575. }
  576. /**
  577. Converts a text device path node to ACPI extension device path structure.
  578. @param TextDeviceNode The input Text device path node.
  579. @return A pointer to the newly-created ACPI extension device path structure.
  580. **/
  581. EFI_DEVICE_PATH_PROTOCOL *
  582. DevPathFromTextAcpiExp (
  583. CHAR16 *TextDeviceNode
  584. )
  585. {
  586. CHAR16 *HIDStr;
  587. CHAR16 *CIDStr;
  588. CHAR16 *UIDSTRStr;
  589. CHAR8 *AsciiStr;
  590. UINT16 Length;
  591. ACPI_EXTENDED_HID_DEVICE_PATH *AcpiEx;
  592. HIDStr = GetNextParamStr (&TextDeviceNode);
  593. CIDStr = GetNextParamStr (&TextDeviceNode);
  594. UIDSTRStr = GetNextParamStr (&TextDeviceNode);
  595. Length = (UINT16) (sizeof (ACPI_EXTENDED_HID_DEVICE_PATH) + StrLen (UIDSTRStr) + 3);
  596. AcpiEx = (ACPI_EXTENDED_HID_DEVICE_PATH *) CreateDeviceNode (
  597. ACPI_DEVICE_PATH,
  598. ACPI_EXTENDED_DP,
  599. Length
  600. );
  601. AcpiEx->HID = EisaIdFromText (HIDStr);
  602. //
  603. // According to UEFI spec, the CID parametr is optional and has a default value of 0.
  604. // So when the CID parametr is not specified or specified as 0 in the text device node.
  605. // Set the CID to 0 in the ACPI extension device path structure.
  606. //
  607. if (*CIDStr == L'\0' || *CIDStr == L'0') {
  608. AcpiEx->CID = 0;
  609. } else {
  610. AcpiEx->CID = EisaIdFromText (CIDStr);
  611. }
  612. AcpiEx->UID = 0;
  613. AsciiStr = (CHAR8 *) ((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
  614. //
  615. // HID string is NULL
  616. //
  617. *AsciiStr = '\0';
  618. //
  619. // Convert UID string
  620. //
  621. AsciiStr++;
  622. StrToAscii (UIDSTRStr, &AsciiStr);
  623. //
  624. // CID string is NULL
  625. //
  626. *AsciiStr = '\0';
  627. return (EFI_DEVICE_PATH_PROTOCOL *) AcpiEx;
  628. }
  629. /**
  630. Converts a text device path node to ACPI _ADR device path structure.
  631. @param TextDeviceNode The input Text device path node.
  632. @return A pointer to the newly-created ACPI _ADR device path structure.
  633. **/
  634. EFI_DEVICE_PATH_PROTOCOL *
  635. DevPathFromTextAcpiAdr (
  636. CHAR16 *TextDeviceNode
  637. )
  638. {
  639. CHAR16 *DisplayDeviceStr;
  640. ACPI_ADR_DEVICE_PATH *AcpiAdr;
  641. UINTN Index;
  642. UINTN Length;
  643. AcpiAdr = (ACPI_ADR_DEVICE_PATH *) CreateDeviceNode (
  644. ACPI_DEVICE_PATH,
  645. ACPI_ADR_DP,
  646. (UINT16) sizeof (ACPI_ADR_DEVICE_PATH)
  647. );
  648. ASSERT (AcpiAdr != NULL);
  649. for (Index = 0; ; Index++) {
  650. DisplayDeviceStr = GetNextParamStr (&TextDeviceNode);
  651. if (IS_NULL (*DisplayDeviceStr)) {
  652. break;
  653. }
  654. if (Index > 0) {
  655. Length = DevicePathNodeLength (AcpiAdr);
  656. AcpiAdr = ReallocatePool (
  657. Length,
  658. Length + sizeof (UINT32),
  659. AcpiAdr
  660. );
  661. ASSERT (AcpiAdr != NULL);
  662. SetDevicePathNodeLength (AcpiAdr, Length + sizeof (UINT32));
  663. }
  664. (&AcpiAdr->ADR)[Index] = (UINT32) Strtoi (DisplayDeviceStr);
  665. }
  666. return (EFI_DEVICE_PATH_PROTOCOL *) AcpiAdr;
  667. }
  668. /**
  669. Converts a generic messaging text device path node to messaging device path structure.
  670. @param TextDeviceNode The input Text device path node.
  671. @return A pointer to messaging device path structure.
  672. **/
  673. EFI_DEVICE_PATH_PROTOCOL *
  674. DevPathFromTextMsg (
  675. CHAR16 *TextDeviceNode
  676. )
  677. {
  678. return DevPathFromTextGenericPath (MESSAGING_DEVICE_PATH, TextDeviceNode);
  679. }
  680. /**
  681. Converts a text device path node to Parallel Port device path structure.
  682. @param TextDeviceNode The input Text device path node.
  683. @return A pointer to the newly-created Parallel Port device path structure.
  684. **/
  685. EFI_DEVICE_PATH_PROTOCOL *
  686. DevPathFromTextAta (
  687. CHAR16 *TextDeviceNode
  688. )
  689. {
  690. CHAR16 *PrimarySecondaryStr;
  691. CHAR16 *SlaveMasterStr;
  692. CHAR16 *LunStr;
  693. ATAPI_DEVICE_PATH *Atapi;
  694. Atapi = (ATAPI_DEVICE_PATH *) CreateDeviceNode (
  695. MESSAGING_DEVICE_PATH,
  696. MSG_ATAPI_DP,
  697. (UINT16) sizeof (ATAPI_DEVICE_PATH)
  698. );
  699. PrimarySecondaryStr = GetNextParamStr (&TextDeviceNode);
  700. SlaveMasterStr = GetNextParamStr (&TextDeviceNode);
  701. LunStr = GetNextParamStr (&TextDeviceNode);
  702. if (StrCmp (PrimarySecondaryStr, L"Primary") == 0) {
  703. Atapi->PrimarySecondary = 0;
  704. } else if (StrCmp (PrimarySecondaryStr, L"Secondary") == 0) {
  705. Atapi->PrimarySecondary = 1;
  706. } else {
  707. Atapi->PrimarySecondary = (UINT8) Strtoi (PrimarySecondaryStr);
  708. }
  709. if (StrCmp (SlaveMasterStr, L"Master") == 0) {
  710. Atapi->SlaveMaster = 0;
  711. } else if (StrCmp (SlaveMasterStr, L"Slave") == 0) {
  712. Atapi->SlaveMaster = 1;
  713. } else {
  714. Atapi->SlaveMaster = (UINT8) Strtoi (SlaveMasterStr);
  715. }
  716. Atapi->Lun = (UINT16) Strtoi (LunStr);
  717. return (EFI_DEVICE_PATH_PROTOCOL *) Atapi;
  718. }
  719. /**
  720. Converts a text device path node to SCSI device path structure.
  721. @param TextDeviceNode The input Text device path node.
  722. @return A pointer to the newly-created SCSI device path structure.
  723. **/
  724. EFI_DEVICE_PATH_PROTOCOL *
  725. DevPathFromTextScsi (
  726. CHAR16 *TextDeviceNode
  727. )
  728. {
  729. CHAR16 *PunStr;
  730. CHAR16 *LunStr;
  731. SCSI_DEVICE_PATH *Scsi;
  732. PunStr = GetNextParamStr (&TextDeviceNode);
  733. LunStr = GetNextParamStr (&TextDeviceNode);
  734. Scsi = (SCSI_DEVICE_PATH *) CreateDeviceNode (
  735. MESSAGING_DEVICE_PATH,
  736. MSG_SCSI_DP,
  737. (UINT16) sizeof (SCSI_DEVICE_PATH)
  738. );
  739. Scsi->Pun = (UINT16) Strtoi (PunStr);
  740. Scsi->Lun = (UINT16) Strtoi (LunStr);
  741. return (EFI_DEVICE_PATH_PROTOCOL *) Scsi;
  742. }
  743. /**
  744. Converts a text device path node to Fibre device path structure.
  745. @param TextDeviceNode The input Text device path node.
  746. @return A pointer to the newly-created Fibre device path structure.
  747. **/
  748. EFI_DEVICE_PATH_PROTOCOL *
  749. DevPathFromTextFibre (
  750. CHAR16 *TextDeviceNode
  751. )
  752. {
  753. CHAR16 *WWNStr;
  754. CHAR16 *LunStr;
  755. FIBRECHANNEL_DEVICE_PATH *Fibre;
  756. WWNStr = GetNextParamStr (&TextDeviceNode);
  757. LunStr = GetNextParamStr (&TextDeviceNode);
  758. Fibre = (FIBRECHANNEL_DEVICE_PATH *) CreateDeviceNode (
  759. MESSAGING_DEVICE_PATH,
  760. MSG_FIBRECHANNEL_DP,
  761. (UINT16) sizeof (FIBRECHANNEL_DEVICE_PATH)
  762. );
  763. Fibre->Reserved = 0;
  764. Strtoi64 (WWNStr, &Fibre->WWN);
  765. Strtoi64 (LunStr, &Fibre->Lun);
  766. return (EFI_DEVICE_PATH_PROTOCOL *) Fibre;
  767. }
  768. /**
  769. Converts a text device path node to FibreEx device path structure.
  770. @param TextDeviceNode The input Text device path node.
  771. @return A pointer to the newly-created FibreEx device path structure.
  772. **/
  773. EFI_DEVICE_PATH_PROTOCOL *
  774. DevPathFromTextFibreEx (
  775. CHAR16 *TextDeviceNode
  776. )
  777. {
  778. CHAR16 *WWNStr;
  779. CHAR16 *LunStr;
  780. FIBRECHANNELEX_DEVICE_PATH *FibreEx;
  781. WWNStr = GetNextParamStr (&TextDeviceNode);
  782. LunStr = GetNextParamStr (&TextDeviceNode);
  783. FibreEx = (FIBRECHANNELEX_DEVICE_PATH *) CreateDeviceNode (
  784. MESSAGING_DEVICE_PATH,
  785. MSG_FIBRECHANNELEX_DP,
  786. (UINT16) sizeof (FIBRECHANNELEX_DEVICE_PATH)
  787. );
  788. FibreEx->Reserved = 0;
  789. Strtoi64 (WWNStr, (UINT64 *) (&FibreEx->WWN));
  790. Strtoi64 (LunStr, (UINT64 *) (&FibreEx->Lun));
  791. *(UINT64 *) (&FibreEx->WWN) = SwapBytes64 (*(UINT64 *) (&FibreEx->WWN));
  792. *(UINT64 *) (&FibreEx->Lun) = SwapBytes64 (*(UINT64 *) (&FibreEx->Lun));
  793. return (EFI_DEVICE_PATH_PROTOCOL *) FibreEx;
  794. }
  795. /**
  796. Converts a text device path node to 1394 device path structure.
  797. @param TextDeviceNode The input Text device path node.
  798. @return A pointer to the newly-created 1394 device path structure.
  799. **/
  800. EFI_DEVICE_PATH_PROTOCOL *
  801. DevPathFromText1394 (
  802. CHAR16 *TextDeviceNode
  803. )
  804. {
  805. CHAR16 *GuidStr;
  806. F1394_DEVICE_PATH *F1394DevPath;
  807. GuidStr = GetNextParamStr (&TextDeviceNode);
  808. F1394DevPath = (F1394_DEVICE_PATH *) CreateDeviceNode (
  809. MESSAGING_DEVICE_PATH,
  810. MSG_1394_DP,
  811. (UINT16) sizeof (F1394_DEVICE_PATH)
  812. );
  813. F1394DevPath->Reserved = 0;
  814. F1394DevPath->Guid = StrHexToUint64 (GuidStr);
  815. return (EFI_DEVICE_PATH_PROTOCOL *) F1394DevPath;
  816. }
  817. /**
  818. Converts a text device path node to USB device path structure.
  819. @param TextDeviceNode The input Text device path node.
  820. @return A pointer to the newly-created USB device path structure.
  821. **/
  822. EFI_DEVICE_PATH_PROTOCOL *
  823. DevPathFromTextUsb (
  824. CHAR16 *TextDeviceNode
  825. )
  826. {
  827. CHAR16 *PortStr;
  828. CHAR16 *InterfaceStr;
  829. USB_DEVICE_PATH *Usb;
  830. PortStr = GetNextParamStr (&TextDeviceNode);
  831. InterfaceStr = GetNextParamStr (&TextDeviceNode);
  832. Usb = (USB_DEVICE_PATH *) CreateDeviceNode (
  833. MESSAGING_DEVICE_PATH,
  834. MSG_USB_DP,
  835. (UINT16) sizeof (USB_DEVICE_PATH)
  836. );
  837. Usb->ParentPortNumber = (UINT8) Strtoi (PortStr);
  838. Usb->InterfaceNumber = (UINT8) Strtoi (InterfaceStr);
  839. return (EFI_DEVICE_PATH_PROTOCOL *) Usb;
  840. }
  841. /**
  842. Converts a text device path node to I20 device path structure.
  843. @param TextDeviceNode The input Text device path node.
  844. @return A pointer to the newly-created I20 device path structure.
  845. **/
  846. EFI_DEVICE_PATH_PROTOCOL *
  847. DevPathFromTextI2O (
  848. CHAR16 *TextDeviceNode
  849. )
  850. {
  851. CHAR16 *TIDStr;
  852. I2O_DEVICE_PATH *I2ODevPath;
  853. TIDStr = GetNextParamStr (&TextDeviceNode);
  854. I2ODevPath = (I2O_DEVICE_PATH *) CreateDeviceNode (
  855. MESSAGING_DEVICE_PATH,
  856. MSG_I2O_DP,
  857. (UINT16) sizeof (I2O_DEVICE_PATH)
  858. );
  859. I2ODevPath->Tid = (UINT32) Strtoi (TIDStr);
  860. return (EFI_DEVICE_PATH_PROTOCOL *) I2ODevPath;
  861. }
  862. /**
  863. Converts a text device path node to Infini Band device path structure.
  864. @param TextDeviceNode The input Text device path node.
  865. @return A pointer to the newly-created Infini Band device path structure.
  866. **/
  867. EFI_DEVICE_PATH_PROTOCOL *
  868. DevPathFromTextInfiniband (
  869. CHAR16 *TextDeviceNode
  870. )
  871. {
  872. CHAR16 *FlagsStr;
  873. CHAR16 *GuidStr;
  874. CHAR16 *SidStr;
  875. CHAR16 *TidStr;
  876. CHAR16 *DidStr;
  877. INFINIBAND_DEVICE_PATH *InfiniBand;
  878. FlagsStr = GetNextParamStr (&TextDeviceNode);
  879. GuidStr = GetNextParamStr (&TextDeviceNode);
  880. SidStr = GetNextParamStr (&TextDeviceNode);
  881. TidStr = GetNextParamStr (&TextDeviceNode);
  882. DidStr = GetNextParamStr (&TextDeviceNode);
  883. InfiniBand = (INFINIBAND_DEVICE_PATH *) CreateDeviceNode (
  884. MESSAGING_DEVICE_PATH,
  885. MSG_INFINIBAND_DP,
  886. (UINT16) sizeof (INFINIBAND_DEVICE_PATH)
  887. );
  888. InfiniBand->ResourceFlags = (UINT32) Strtoi (FlagsStr);
  889. StrToGuid (GuidStr, (EFI_GUID *) InfiniBand->PortGid);
  890. Strtoi64 (SidStr, &InfiniBand->ServiceId);
  891. Strtoi64 (TidStr, &InfiniBand->TargetPortId);
  892. Strtoi64 (DidStr, &InfiniBand->DeviceId);
  893. return (EFI_DEVICE_PATH_PROTOCOL *) InfiniBand;
  894. }
  895. /**
  896. Converts a text device path node to Vendor-Defined Messaging device path structure.
  897. @param TextDeviceNode The input Text device path node.
  898. @return A pointer to the newly-created Vendor-Defined Messaging device path structure.
  899. **/
  900. EFI_DEVICE_PATH_PROTOCOL *
  901. DevPathFromTextVenMsg (
  902. CHAR16 *TextDeviceNode
  903. )
  904. {
  905. return ConvertFromTextVendor (
  906. TextDeviceNode,
  907. MESSAGING_DEVICE_PATH,
  908. MSG_VENDOR_DP
  909. );
  910. }
  911. /**
  912. Converts a text device path node to Vendor defined PC-ANSI device path structure.
  913. @param TextDeviceNode The input Text device path node.
  914. @return A pointer to the newly-created Vendor defined PC-ANSI device path structure.
  915. **/
  916. EFI_DEVICE_PATH_PROTOCOL *
  917. DevPathFromTextVenPcAnsi (
  918. CHAR16 *TextDeviceNode
  919. )
  920. {
  921. VENDOR_DEVICE_PATH *Vendor;
  922. Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
  923. MESSAGING_DEVICE_PATH,
  924. MSG_VENDOR_DP,
  925. (UINT16) sizeof (VENDOR_DEVICE_PATH));
  926. CopyGuid (&Vendor->Guid, &gEfiPcAnsiGuid);
  927. return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
  928. }
  929. /**
  930. Converts a text device path node to Vendor defined VT100 device path structure.
  931. @param TextDeviceNode The input Text device path node.
  932. @return A pointer to the newly-created Vendor defined VT100 device path structure.
  933. **/
  934. EFI_DEVICE_PATH_PROTOCOL *
  935. DevPathFromTextVenVt100 (
  936. CHAR16 *TextDeviceNode
  937. )
  938. {
  939. VENDOR_DEVICE_PATH *Vendor;
  940. Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
  941. MESSAGING_DEVICE_PATH,
  942. MSG_VENDOR_DP,
  943. (UINT16) sizeof (VENDOR_DEVICE_PATH));
  944. CopyGuid (&Vendor->Guid, &gEfiVT100Guid);
  945. return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
  946. }
  947. /**
  948. Converts a text device path node to Vendor defined VT100 Plus device path structure.
  949. @param TextDeviceNode The input Text device path node.
  950. @return A pointer to the newly-created Vendor defined VT100 Plus device path structure.
  951. **/
  952. EFI_DEVICE_PATH_PROTOCOL *
  953. DevPathFromTextVenVt100Plus (
  954. CHAR16 *TextDeviceNode
  955. )
  956. {
  957. VENDOR_DEVICE_PATH *Vendor;
  958. Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
  959. MESSAGING_DEVICE_PATH,
  960. MSG_VENDOR_DP,
  961. (UINT16) sizeof (VENDOR_DEVICE_PATH));
  962. CopyGuid (&Vendor->Guid, &gEfiVT100PlusGuid);
  963. return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
  964. }
  965. /**
  966. Converts a text device path node to Vendor defined UTF8 device path structure.
  967. @param TextDeviceNode The input Text device path node.
  968. @return A pointer to the newly-created Vendor defined UTF8 device path structure.
  969. **/
  970. EFI_DEVICE_PATH_PROTOCOL *
  971. DevPathFromTextVenUtf8 (
  972. CHAR16 *TextDeviceNode
  973. )
  974. {
  975. VENDOR_DEVICE_PATH *Vendor;
  976. Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
  977. MESSAGING_DEVICE_PATH,
  978. MSG_VENDOR_DP,
  979. (UINT16) sizeof (VENDOR_DEVICE_PATH));
  980. CopyGuid (&Vendor->Guid, &gEfiVTUTF8Guid);
  981. return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
  982. }
  983. /**
  984. Converts a text device path node to UART Flow Control device path structure.
  985. @param TextDeviceNode The input Text device path node.
  986. @return A pointer to the newly-created UART Flow Control device path structure.
  987. **/
  988. EFI_DEVICE_PATH_PROTOCOL *
  989. DevPathFromTextUartFlowCtrl (
  990. CHAR16 *TextDeviceNode
  991. )
  992. {
  993. CHAR16 *ValueStr;
  994. UART_FLOW_CONTROL_DEVICE_PATH *UartFlowControl;
  995. ValueStr = GetNextParamStr (&TextDeviceNode);
  996. UartFlowControl = (UART_FLOW_CONTROL_DEVICE_PATH *) CreateDeviceNode (
  997. MESSAGING_DEVICE_PATH,
  998. MSG_VENDOR_DP,
  999. (UINT16) sizeof (UART_FLOW_CONTROL_DEVICE_PATH)
  1000. );
  1001. CopyGuid (&UartFlowControl->Guid, &gEfiUartDevicePathGuid);
  1002. if (StrCmp (ValueStr, L"XonXoff") == 0) {
  1003. UartFlowControl->FlowControlMap = 2;
  1004. } else if (StrCmp (ValueStr, L"Hardware") == 0) {
  1005. UartFlowControl->FlowControlMap = 1;
  1006. } else {
  1007. UartFlowControl->FlowControlMap = 0;
  1008. }
  1009. return (EFI_DEVICE_PATH_PROTOCOL *) UartFlowControl;
  1010. }
  1011. /**
  1012. Converts a text device path node to Serial Attached SCSI device path structure.
  1013. @param TextDeviceNode The input Text device path node.
  1014. @return A pointer to the newly-created Serial Attached SCSI device path structure.
  1015. **/
  1016. EFI_DEVICE_PATH_PROTOCOL *
  1017. DevPathFromTextSAS (
  1018. CHAR16 *TextDeviceNode
  1019. )
  1020. {
  1021. CHAR16 *AddressStr;
  1022. CHAR16 *LunStr;
  1023. CHAR16 *RTPStr;
  1024. CHAR16 *SASSATAStr;
  1025. CHAR16 *LocationStr;
  1026. CHAR16 *ConnectStr;
  1027. CHAR16 *DriveBayStr;
  1028. CHAR16 *ReservedStr;
  1029. UINT16 Info;
  1030. UINT16 Uint16;
  1031. SAS_DEVICE_PATH *Sas;
  1032. AddressStr = GetNextParamStr (&TextDeviceNode);
  1033. LunStr = GetNextParamStr (&TextDeviceNode);
  1034. RTPStr = GetNextParamStr (&TextDeviceNode);
  1035. SASSATAStr = GetNextParamStr (&TextDeviceNode);
  1036. LocationStr = GetNextParamStr (&TextDeviceNode);
  1037. ConnectStr = GetNextParamStr (&TextDeviceNode);
  1038. DriveBayStr = GetNextParamStr (&TextDeviceNode);
  1039. ReservedStr = GetNextParamStr (&TextDeviceNode);
  1040. Sas = (SAS_DEVICE_PATH *) CreateDeviceNode (
  1041. MESSAGING_DEVICE_PATH,
  1042. MSG_VENDOR_DP,
  1043. (UINT16) sizeof (SAS_DEVICE_PATH)
  1044. );
  1045. CopyGuid (&Sas->Guid, &gEfiSasDevicePathGuid);
  1046. Strtoi64 (AddressStr, &Sas->SasAddress);
  1047. Strtoi64 (LunStr, &Sas->Lun);
  1048. Sas->RelativeTargetPort = (UINT16) Strtoi (RTPStr);
  1049. if (StrCmp (SASSATAStr, L"NoTopology") == 0) {
  1050. Info = 0x0;
  1051. } else if ((StrCmp (SASSATAStr, L"SATA") == 0) || (StrCmp (SASSATAStr, L"SAS") == 0)) {
  1052. Uint16 = (UINT16) Strtoi (DriveBayStr);
  1053. if (Uint16 == 0) {
  1054. Info = 0x1;
  1055. } else {
  1056. Info = (UINT16) (0x2 | ((Uint16 - 1) << 8));
  1057. }
  1058. if (StrCmp (SASSATAStr, L"SATA") == 0) {
  1059. Info |= BIT4;
  1060. }
  1061. //
  1062. // Location is an integer between 0 and 1 or else
  1063. // the keyword Internal (0) or External (1).
  1064. //
  1065. if (StrCmp (LocationStr, L"External") == 0) {
  1066. Uint16 = 1;
  1067. } else if (StrCmp (LocationStr, L"Internal") == 0) {
  1068. Uint16 = 0;
  1069. } else {
  1070. Uint16 = ((UINT16) Strtoi (LocationStr) & BIT0);
  1071. }
  1072. Info |= (Uint16 << 5);
  1073. //
  1074. // Connect is an integer between 0 and 3 or else
  1075. // the keyword Direct (0) or Expanded (1).
  1076. //
  1077. if (StrCmp (ConnectStr, L"Expanded") == 0) {
  1078. Uint16 = 1;
  1079. } else if (StrCmp (ConnectStr, L"Direct") == 0) {
  1080. Uint16 = 0;
  1081. } else {
  1082. Uint16 = ((UINT16) Strtoi (ConnectStr) & (BIT0 | BIT1));
  1083. }
  1084. Info |= (Uint16 << 6);
  1085. } else {
  1086. Info = (UINT16) Strtoi (SASSATAStr);
  1087. }
  1088. Sas->DeviceTopology = Info;
  1089. Sas->Reserved = (UINT32) Strtoi (ReservedStr);
  1090. return (EFI_DEVICE_PATH_PROTOCOL *) Sas;
  1091. }
  1092. /**
  1093. Converts a text device path node to Serial Attached SCSI Ex device path structure.
  1094. @param TextDeviceNode The input Text device path node.
  1095. @return A pointer to the newly-created Serial Attached SCSI Ex device path structure.
  1096. **/
  1097. EFI_DEVICE_PATH_PROTOCOL *
  1098. DevPathFromTextSasEx (
  1099. CHAR16 *TextDeviceNode
  1100. )
  1101. {
  1102. CHAR16 *AddressStr;
  1103. CHAR16 *LunStr;
  1104. CHAR16 *RTPStr;
  1105. CHAR16 *SASSATAStr;
  1106. CHAR16 *LocationStr;
  1107. CHAR16 *ConnectStr;
  1108. CHAR16 *DriveBayStr;
  1109. UINT16 Info;
  1110. UINT16 Uint16;
  1111. UINT64 SasAddress;
  1112. UINT64 Lun;
  1113. SASEX_DEVICE_PATH *SasEx;
  1114. AddressStr = GetNextParamStr (&TextDeviceNode);
  1115. LunStr = GetNextParamStr (&TextDeviceNode);
  1116. RTPStr = GetNextParamStr (&TextDeviceNode);
  1117. SASSATAStr = GetNextParamStr (&TextDeviceNode);
  1118. LocationStr = GetNextParamStr (&TextDeviceNode);
  1119. ConnectStr = GetNextParamStr (&TextDeviceNode);
  1120. DriveBayStr = GetNextParamStr (&TextDeviceNode);
  1121. SasEx = (SASEX_DEVICE_PATH *) CreateDeviceNode (
  1122. MESSAGING_DEVICE_PATH,
  1123. MSG_SASEX_DP,
  1124. (UINT16) sizeof (SASEX_DEVICE_PATH)
  1125. );
  1126. Strtoi64 (AddressStr, &SasAddress);
  1127. Strtoi64 (LunStr, &Lun);
  1128. WriteUnaligned64 ((UINT64 *) &SasEx->SasAddress, SwapBytes64 (SasAddress));
  1129. WriteUnaligned64 ((UINT64 *) &SasEx->Lun, SwapBytes64 (Lun));
  1130. SasEx->RelativeTargetPort = (UINT16) Strtoi (RTPStr);
  1131. if (StrCmp (SASSATAStr, L"NoTopology") == 0) {
  1132. Info = 0x0;
  1133. } else if ((StrCmp (SASSATAStr, L"SATA") == 0) || (StrCmp (SASSATAStr, L"SAS") == 0)) {
  1134. Uint16 = (UINT16) Strtoi (DriveBayStr);
  1135. if (Uint16 == 0) {
  1136. Info = 0x1;
  1137. } else {
  1138. Info = (UINT16) (0x2 | ((Uint16 - 1) << 8));
  1139. }
  1140. if (StrCmp (SASSATAStr, L"SATA") == 0) {
  1141. Info |= BIT4;
  1142. }
  1143. //
  1144. // Location is an integer between 0 and 1 or else
  1145. // the keyword Internal (0) or External (1).
  1146. //
  1147. if (StrCmp (LocationStr, L"External") == 0) {
  1148. Uint16 = 1;
  1149. } else if (StrCmp (LocationStr, L"Internal") == 0) {
  1150. Uint16 = 0;
  1151. } else {
  1152. Uint16 = ((UINT16) Strtoi (LocationStr) & BIT0);
  1153. }
  1154. Info |= (Uint16 << 5);
  1155. //
  1156. // Connect is an integer between 0 and 3 or else
  1157. // the keyword Direct (0) or Expanded (1).
  1158. //
  1159. if (StrCmp (ConnectStr, L"Expanded") == 0) {
  1160. Uint16 = 1;
  1161. } else if (StrCmp (ConnectStr, L"Direct") == 0) {
  1162. Uint16 = 0;
  1163. } else {
  1164. Uint16 = ((UINT16) Strtoi (ConnectStr) & (BIT0 | BIT1));
  1165. }
  1166. Info |= (Uint16 << 6);
  1167. } else {
  1168. Info = (UINT16) Strtoi (SASSATAStr);
  1169. }
  1170. SasEx->DeviceTopology = Info;
  1171. return (EFI_DEVICE_PATH_PROTOCOL *) SasEx;
  1172. }
  1173. /**
  1174. Converts a text device path node to NVM Express Namespace device path structure.
  1175. @param TextDeviceNode The input Text device path node.
  1176. @return A pointer to the newly-created NVM Express Namespace device path structure.
  1177. **/
  1178. EFI_DEVICE_PATH_PROTOCOL *
  1179. DevPathFromTextNVMe (
  1180. CHAR16 *TextDeviceNode
  1181. )
  1182. {
  1183. CHAR16 *NamespaceIdStr;
  1184. CHAR16 *NamespaceUuidStr;
  1185. NVME_NAMESPACE_DEVICE_PATH *Nvme;
  1186. UINT8 *Uuid;
  1187. UINTN Index;
  1188. NamespaceIdStr = GetNextParamStr (&TextDeviceNode);
  1189. NamespaceUuidStr = GetNextParamStr (&TextDeviceNode);
  1190. Nvme = (NVME_NAMESPACE_DEVICE_PATH *) CreateDeviceNode (
  1191. MESSAGING_DEVICE_PATH,
  1192. MSG_NVME_NAMESPACE_DP,
  1193. (UINT16) sizeof (NVME_NAMESPACE_DEVICE_PATH)
  1194. );
  1195. Nvme->NamespaceId = (UINT32) Strtoi (NamespaceIdStr);
  1196. Uuid = (UINT8 *) &Nvme->NamespaceUuid;
  1197. Index = sizeof (Nvme->NamespaceUuid) / sizeof (UINT8);
  1198. while (Index-- != 0) {
  1199. Uuid[Index] = (UINT8) StrHexToUint64 (SplitStr (&NamespaceUuidStr, L'-'));
  1200. }
  1201. return (EFI_DEVICE_PATH_PROTOCOL *) Nvme;
  1202. }
  1203. /**
  1204. Converts a text device path node to UFS device path structure.
  1205. @param TextDeviceNode The input Text device path node.
  1206. @return A pointer to the newly-created UFS device path structure.
  1207. **/
  1208. EFI_DEVICE_PATH_PROTOCOL *
  1209. DevPathFromTextUfs (
  1210. CHAR16 *TextDeviceNode
  1211. )
  1212. {
  1213. CHAR16 *PunStr;
  1214. CHAR16 *LunStr;
  1215. UFS_DEVICE_PATH *Ufs;
  1216. PunStr = GetNextParamStr (&TextDeviceNode);
  1217. LunStr = GetNextParamStr (&TextDeviceNode);
  1218. Ufs = (UFS_DEVICE_PATH *) CreateDeviceNode (
  1219. MESSAGING_DEVICE_PATH,
  1220. MSG_UFS_DP,
  1221. (UINT16) sizeof (UFS_DEVICE_PATH)
  1222. );
  1223. Ufs->Pun = (UINT8) Strtoi (PunStr);
  1224. Ufs->Lun = (UINT8) Strtoi (LunStr);
  1225. return (EFI_DEVICE_PATH_PROTOCOL *) Ufs;
  1226. }
  1227. /**
  1228. Converts a text device path node to SD (Secure Digital) device path structure.
  1229. @param TextDeviceNode The input Text device path node.
  1230. @return A pointer to the newly-created SD device path structure.
  1231. **/
  1232. EFI_DEVICE_PATH_PROTOCOL *
  1233. DevPathFromTextSd (
  1234. CHAR16 *TextDeviceNode
  1235. )
  1236. {
  1237. CHAR16 *SlotNumberStr;
  1238. SD_DEVICE_PATH *Sd;
  1239. SlotNumberStr = GetNextParamStr (&TextDeviceNode);
  1240. Sd = (SD_DEVICE_PATH *) CreateDeviceNode (
  1241. MESSAGING_DEVICE_PATH,
  1242. MSG_SD_DP,
  1243. (UINT16) sizeof (SD_DEVICE_PATH)
  1244. );
  1245. Sd->SlotNumber = (UINT8) Strtoi (SlotNumberStr);
  1246. return (EFI_DEVICE_PATH_PROTOCOL *) Sd;
  1247. }
  1248. /**
  1249. Converts a text device path node to EMMC (Embedded MMC) device path structure.
  1250. @param TextDeviceNode The input Text device path node.
  1251. @return A pointer to the newly-created EMMC device path structure.
  1252. **/
  1253. EFI_DEVICE_PATH_PROTOCOL *
  1254. DevPathFromTextEmmc (
  1255. CHAR16 *TextDeviceNode
  1256. )
  1257. {
  1258. CHAR16 *SlotNumberStr;
  1259. EMMC_DEVICE_PATH *Emmc;
  1260. SlotNumberStr = GetNextParamStr (&TextDeviceNode);
  1261. Emmc = (EMMC_DEVICE_PATH *) CreateDeviceNode (
  1262. MESSAGING_DEVICE_PATH,
  1263. MSG_EMMC_DP,
  1264. (UINT16) sizeof (EMMC_DEVICE_PATH)
  1265. );
  1266. Emmc->SlotNumber = (UINT8) Strtoi (SlotNumberStr);
  1267. return (EFI_DEVICE_PATH_PROTOCOL *) Emmc;
  1268. }
  1269. /**
  1270. Converts a text device path node to Debug Port device path structure.
  1271. @param TextDeviceNode The input Text device path node.
  1272. @return A pointer to the newly-created Debug Port device path structure.
  1273. **/
  1274. EFI_DEVICE_PATH_PROTOCOL *
  1275. DevPathFromTextDebugPort (
  1276. CHAR16 *TextDeviceNode
  1277. )
  1278. {
  1279. VENDOR_DEVICE_PATH *Vend;
  1280. Vend = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
  1281. MESSAGING_DEVICE_PATH,
  1282. MSG_VENDOR_DP,
  1283. (UINT16) sizeof (VENDOR_DEVICE_PATH)
  1284. );
  1285. CopyGuid (&Vend->Guid, &gEfiDebugPortProtocolGuid);
  1286. return (EFI_DEVICE_PATH_PROTOCOL *) Vend;
  1287. }
  1288. /**
  1289. Converts a text device path node to MAC device path structure.
  1290. @param TextDeviceNode The input Text device path node.
  1291. @return A pointer to the newly-created MAC device path structure.
  1292. **/
  1293. EFI_DEVICE_PATH_PROTOCOL *
  1294. DevPathFromTextMAC (
  1295. CHAR16 *TextDeviceNode
  1296. )
  1297. {
  1298. CHAR16 *AddressStr;
  1299. CHAR16 *IfTypeStr;
  1300. UINTN Length;
  1301. MAC_ADDR_DEVICE_PATH *MACDevPath;
  1302. AddressStr = GetNextParamStr (&TextDeviceNode);
  1303. IfTypeStr = GetNextParamStr (&TextDeviceNode);
  1304. MACDevPath = (MAC_ADDR_DEVICE_PATH *) CreateDeviceNode (
  1305. MESSAGING_DEVICE_PATH,
  1306. MSG_MAC_ADDR_DP,
  1307. (UINT16) sizeof (MAC_ADDR_DEVICE_PATH)
  1308. );
  1309. MACDevPath->IfType = (UINT8) Strtoi (IfTypeStr);
  1310. Length = sizeof (EFI_MAC_ADDRESS);
  1311. if (MACDevPath->IfType == 0x01 || MACDevPath->IfType == 0x00) {
  1312. Length = 6;
  1313. }
  1314. StrHexToBytes (AddressStr, Length * 2, MACDevPath->MacAddress.Addr, Length);
  1315. return (EFI_DEVICE_PATH_PROTOCOL *) MACDevPath;
  1316. }
  1317. /**
  1318. Converts a text format to the network protocol ID.
  1319. @param Text String of protocol field.
  1320. @return Network protocol ID .
  1321. **/
  1322. UINTN
  1323. NetworkProtocolFromText (
  1324. CHAR16 *Text
  1325. )
  1326. {
  1327. if (StrCmp (Text, L"UDP") == 0) {
  1328. return RFC_1700_UDP_PROTOCOL;
  1329. }
  1330. if (StrCmp (Text, L"TCP") == 0) {
  1331. return RFC_1700_TCP_PROTOCOL;
  1332. }
  1333. return Strtoi (Text);
  1334. }
  1335. /**
  1336. Converts a text device path node to IPV4 device path structure.
  1337. @param TextDeviceNode The input Text device path node.
  1338. @return A pointer to the newly-created IPV4 device path structure.
  1339. **/
  1340. EFI_DEVICE_PATH_PROTOCOL *
  1341. DevPathFromTextIPv4 (
  1342. CHAR16 *TextDeviceNode
  1343. )
  1344. {
  1345. CHAR16 *RemoteIPStr;
  1346. CHAR16 *ProtocolStr;
  1347. CHAR16 *TypeStr;
  1348. CHAR16 *LocalIPStr;
  1349. CHAR16 *GatewayIPStr;
  1350. CHAR16 *SubnetMaskStr;
  1351. IPv4_DEVICE_PATH *IPv4;
  1352. RemoteIPStr = GetNextParamStr (&TextDeviceNode);
  1353. ProtocolStr = GetNextParamStr (&TextDeviceNode);
  1354. TypeStr = GetNextParamStr (&TextDeviceNode);
  1355. LocalIPStr = GetNextParamStr (&TextDeviceNode);
  1356. GatewayIPStr = GetNextParamStr (&TextDeviceNode);
  1357. SubnetMaskStr = GetNextParamStr (&TextDeviceNode);
  1358. IPv4 = (IPv4_DEVICE_PATH *) CreateDeviceNode (
  1359. MESSAGING_DEVICE_PATH,
  1360. MSG_IPv4_DP,
  1361. (UINT16) sizeof (IPv4_DEVICE_PATH)
  1362. );
  1363. StrToIpv4Address (RemoteIPStr, NULL, &IPv4->RemoteIpAddress, NULL);
  1364. IPv4->Protocol = (UINT16) NetworkProtocolFromText (ProtocolStr);
  1365. if (StrCmp (TypeStr, L"Static") == 0) {
  1366. IPv4->StaticIpAddress = TRUE;
  1367. } else {
  1368. IPv4->StaticIpAddress = FALSE;
  1369. }
  1370. StrToIpv4Address (LocalIPStr, NULL, &IPv4->LocalIpAddress, NULL);
  1371. if (!IS_NULL (*GatewayIPStr) && !IS_NULL (*SubnetMaskStr)) {
  1372. StrToIpv4Address (GatewayIPStr, NULL, &IPv4->GatewayIpAddress, NULL);
  1373. StrToIpv4Address (SubnetMaskStr, NULL, &IPv4->SubnetMask, NULL);
  1374. } else {
  1375. ZeroMem (&IPv4->GatewayIpAddress, sizeof (IPv4->GatewayIpAddress));
  1376. ZeroMem (&IPv4->SubnetMask, sizeof (IPv4->SubnetMask));
  1377. }
  1378. IPv4->LocalPort = 0;
  1379. IPv4->RemotePort = 0;
  1380. return (EFI_DEVICE_PATH_PROTOCOL *) IPv4;
  1381. }
  1382. /**
  1383. Converts a text device path node to IPV6 device path structure.
  1384. @param TextDeviceNode The input Text device path node.
  1385. @return A pointer to the newly-created IPV6 device path structure.
  1386. **/
  1387. EFI_DEVICE_PATH_PROTOCOL *
  1388. DevPathFromTextIPv6 (
  1389. CHAR16 *TextDeviceNode
  1390. )
  1391. {
  1392. CHAR16 *RemoteIPStr;
  1393. CHAR16 *ProtocolStr;
  1394. CHAR16 *TypeStr;
  1395. CHAR16 *LocalIPStr;
  1396. CHAR16 *GatewayIPStr;
  1397. CHAR16 *PrefixLengthStr;
  1398. IPv6_DEVICE_PATH *IPv6;
  1399. RemoteIPStr = GetNextParamStr (&TextDeviceNode);
  1400. ProtocolStr = GetNextParamStr (&TextDeviceNode);
  1401. TypeStr = GetNextParamStr (&TextDeviceNode);
  1402. LocalIPStr = GetNextParamStr (&TextDeviceNode);
  1403. PrefixLengthStr = GetNextParamStr (&TextDeviceNode);
  1404. GatewayIPStr = GetNextParamStr (&TextDeviceNode);
  1405. IPv6 = (IPv6_DEVICE_PATH *) CreateDeviceNode (
  1406. MESSAGING_DEVICE_PATH,
  1407. MSG_IPv6_DP,
  1408. (UINT16) sizeof (IPv6_DEVICE_PATH)
  1409. );
  1410. StrToIpv6Address (RemoteIPStr, NULL, &IPv6->RemoteIpAddress, NULL);
  1411. IPv6->Protocol = (UINT16) NetworkProtocolFromText (ProtocolStr);
  1412. if (StrCmp (TypeStr, L"Static") == 0) {
  1413. IPv6->IpAddressOrigin = 0;
  1414. } else if (StrCmp (TypeStr, L"StatelessAutoConfigure") == 0) {
  1415. IPv6->IpAddressOrigin = 1;
  1416. } else {
  1417. IPv6->IpAddressOrigin = 2;
  1418. }
  1419. StrToIpv6Address (LocalIPStr, NULL, &IPv6->LocalIpAddress, NULL);
  1420. if (!IS_NULL (*GatewayIPStr) && !IS_NULL (*PrefixLengthStr)) {
  1421. StrToIpv6Address (GatewayIPStr, NULL, &IPv6->GatewayIpAddress, NULL);
  1422. IPv6->PrefixLength = (UINT8) Strtoi (PrefixLengthStr);
  1423. } else {
  1424. ZeroMem (&IPv6->GatewayIpAddress, sizeof (IPv6->GatewayIpAddress));
  1425. IPv6->PrefixLength = 0;
  1426. }
  1427. IPv6->LocalPort = 0;
  1428. IPv6->RemotePort = 0;
  1429. return (EFI_DEVICE_PATH_PROTOCOL *) IPv6;
  1430. }
  1431. /**
  1432. Converts a text device path node to UART device path structure.
  1433. @param TextDeviceNode The input Text device path node.
  1434. @return A pointer to the newly-created UART device path structure.
  1435. **/
  1436. EFI_DEVICE_PATH_PROTOCOL *
  1437. DevPathFromTextUart (
  1438. CHAR16 *TextDeviceNode
  1439. )
  1440. {
  1441. CHAR16 *BaudStr;
  1442. CHAR16 *DataBitsStr;
  1443. CHAR16 *ParityStr;
  1444. CHAR16 *StopBitsStr;
  1445. UART_DEVICE_PATH *Uart;
  1446. BaudStr = GetNextParamStr (&TextDeviceNode);
  1447. DataBitsStr = GetNextParamStr (&TextDeviceNode);
  1448. ParityStr = GetNextParamStr (&TextDeviceNode);
  1449. StopBitsStr = GetNextParamStr (&TextDeviceNode);
  1450. Uart = (UART_DEVICE_PATH *) CreateDeviceNode (
  1451. MESSAGING_DEVICE_PATH,
  1452. MSG_UART_DP,
  1453. (UINT16) sizeof (UART_DEVICE_PATH)
  1454. );
  1455. if (StrCmp (BaudStr, L"DEFAULT") == 0) {
  1456. Uart->BaudRate = 115200;
  1457. } else {
  1458. Strtoi64 (BaudStr, &Uart->BaudRate);
  1459. }
  1460. Uart->DataBits = (UINT8) ((StrCmp (DataBitsStr, L"DEFAULT") == 0) ? 8 : Strtoi (DataBitsStr));
  1461. switch (*ParityStr) {
  1462. case L'D':
  1463. Uart->Parity = 0;
  1464. break;
  1465. case L'N':
  1466. Uart->Parity = 1;
  1467. break;
  1468. case L'E':
  1469. Uart->Parity = 2;
  1470. break;
  1471. case L'O':
  1472. Uart->Parity = 3;
  1473. break;
  1474. case L'M':
  1475. Uart->Parity = 4;
  1476. break;
  1477. case L'S':
  1478. Uart->Parity = 5;
  1479. break;
  1480. default:
  1481. Uart->Parity = (UINT8) Strtoi (ParityStr);
  1482. break;
  1483. }
  1484. if (StrCmp (StopBitsStr, L"D") == 0) {
  1485. Uart->StopBits = (UINT8) 0;
  1486. } else if (StrCmp (StopBitsStr, L"1") == 0) {
  1487. Uart->StopBits = (UINT8) 1;
  1488. } else if (StrCmp (StopBitsStr, L"1.5") == 0) {
  1489. Uart->StopBits = (UINT8) 2;
  1490. } else if (StrCmp (StopBitsStr, L"2") == 0) {
  1491. Uart->StopBits = (UINT8) 3;
  1492. } else {
  1493. Uart->StopBits = (UINT8) Strtoi (StopBitsStr);
  1494. }
  1495. return (EFI_DEVICE_PATH_PROTOCOL *) Uart;
  1496. }
  1497. /**
  1498. Converts a text device path node to USB class device path structure.
  1499. @param TextDeviceNode The input Text device path node.
  1500. @param UsbClassText A pointer to USB_CLASS_TEXT structure to be integrated to USB Class Text.
  1501. @return A pointer to the newly-created USB class device path structure.
  1502. **/
  1503. EFI_DEVICE_PATH_PROTOCOL *
  1504. ConvertFromTextUsbClass (
  1505. CHAR16 *TextDeviceNode,
  1506. USB_CLASS_TEXT *UsbClassText
  1507. )
  1508. {
  1509. CHAR16 *VIDStr;
  1510. CHAR16 *PIDStr;
  1511. CHAR16 *ClassStr;
  1512. CHAR16 *SubClassStr;
  1513. CHAR16 *ProtocolStr;
  1514. USB_CLASS_DEVICE_PATH *UsbClass;
  1515. UsbClass = (USB_CLASS_DEVICE_PATH *) CreateDeviceNode (
  1516. MESSAGING_DEVICE_PATH,
  1517. MSG_USB_CLASS_DP,
  1518. (UINT16) sizeof (USB_CLASS_DEVICE_PATH)
  1519. );
  1520. VIDStr = GetNextParamStr (&TextDeviceNode);
  1521. PIDStr = GetNextParamStr (&TextDeviceNode);
  1522. if (UsbClassText->ClassExist) {
  1523. ClassStr = GetNextParamStr (&TextDeviceNode);
  1524. if (*ClassStr == L'\0') {
  1525. UsbClass->DeviceClass = 0xFF;
  1526. } else {
  1527. UsbClass->DeviceClass = (UINT8) Strtoi (ClassStr);
  1528. }
  1529. } else {
  1530. UsbClass->DeviceClass = UsbClassText->Class;
  1531. }
  1532. if (UsbClassText->SubClassExist) {
  1533. SubClassStr = GetNextParamStr (&TextDeviceNode);
  1534. if (*SubClassStr == L'\0') {
  1535. UsbClass->DeviceSubClass = 0xFF;
  1536. } else {
  1537. UsbClass->DeviceSubClass = (UINT8) Strtoi (SubClassStr);
  1538. }
  1539. } else {
  1540. UsbClass->DeviceSubClass = UsbClassText->SubClass;
  1541. }
  1542. ProtocolStr = GetNextParamStr (&TextDeviceNode);
  1543. if (*VIDStr == L'\0') {
  1544. UsbClass->VendorId = 0xFFFF;
  1545. } else {
  1546. UsbClass->VendorId = (UINT16) Strtoi (VIDStr);
  1547. }
  1548. if (*PIDStr == L'\0') {
  1549. UsbClass->ProductId = 0xFFFF;
  1550. } else {
  1551. UsbClass->ProductId = (UINT16) Strtoi (PIDStr);
  1552. }
  1553. if (*ProtocolStr == L'\0') {
  1554. UsbClass->DeviceProtocol = 0xFF;
  1555. } else {
  1556. UsbClass->DeviceProtocol = (UINT8) Strtoi (ProtocolStr);
  1557. }
  1558. return (EFI_DEVICE_PATH_PROTOCOL *) UsbClass;
  1559. }
  1560. /**
  1561. Converts a text device path node to USB class device path structure.
  1562. @param TextDeviceNode The input Text device path node.
  1563. @return A pointer to the newly-created USB class device path structure.
  1564. **/
  1565. EFI_DEVICE_PATH_PROTOCOL *
  1566. DevPathFromTextUsbClass (
  1567. CHAR16 *TextDeviceNode
  1568. )
  1569. {
  1570. USB_CLASS_TEXT UsbClassText;
  1571. UsbClassText.ClassExist = TRUE;
  1572. UsbClassText.SubClassExist = TRUE;
  1573. return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
  1574. }
  1575. /**
  1576. Converts a text device path node to USB audio device path structure.
  1577. @param TextDeviceNode The input Text device path node.
  1578. @return A pointer to the newly-created USB audio device path structure.
  1579. **/
  1580. EFI_DEVICE_PATH_PROTOCOL *
  1581. DevPathFromTextUsbAudio (
  1582. CHAR16 *TextDeviceNode
  1583. )
  1584. {
  1585. USB_CLASS_TEXT UsbClassText;
  1586. UsbClassText.ClassExist = FALSE;
  1587. UsbClassText.Class = USB_CLASS_AUDIO;
  1588. UsbClassText.SubClassExist = TRUE;
  1589. return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
  1590. }
  1591. /**
  1592. Converts a text device path node to USB CDC Control device path structure.
  1593. @param TextDeviceNode The input Text device path node.
  1594. @return A pointer to the newly-created USB CDC Control device path structure.
  1595. **/
  1596. EFI_DEVICE_PATH_PROTOCOL *
  1597. DevPathFromTextUsbCDCControl (
  1598. CHAR16 *TextDeviceNode
  1599. )
  1600. {
  1601. USB_CLASS_TEXT UsbClassText;
  1602. UsbClassText.ClassExist = FALSE;
  1603. UsbClassText.Class = USB_CLASS_CDCCONTROL;
  1604. UsbClassText.SubClassExist = TRUE;
  1605. return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
  1606. }
  1607. /**
  1608. Converts a text device path node to USB HID device path structure.
  1609. @param TextDeviceNode The input Text device path node.
  1610. @return A pointer to the newly-created USB HID device path structure.
  1611. **/
  1612. EFI_DEVICE_PATH_PROTOCOL *
  1613. DevPathFromTextUsbHID (
  1614. CHAR16 *TextDeviceNode
  1615. )
  1616. {
  1617. USB_CLASS_TEXT UsbClassText;
  1618. UsbClassText.ClassExist = FALSE;
  1619. UsbClassText.Class = USB_CLASS_HID;
  1620. UsbClassText.SubClassExist = TRUE;
  1621. return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
  1622. }
  1623. /**
  1624. Converts a text device path node to USB Image device path structure.
  1625. @param TextDeviceNode The input Text device path node.
  1626. @return A pointer to the newly-created USB Image device path structure.
  1627. **/
  1628. EFI_DEVICE_PATH_PROTOCOL *
  1629. DevPathFromTextUsbImage (
  1630. CHAR16 *TextDeviceNode
  1631. )
  1632. {
  1633. USB_CLASS_TEXT UsbClassText;
  1634. UsbClassText.ClassExist = FALSE;
  1635. UsbClassText.Class = USB_CLASS_IMAGE;
  1636. UsbClassText.SubClassExist = TRUE;
  1637. return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
  1638. }
  1639. /**
  1640. Converts a text device path node to USB Print device path structure.
  1641. @param TextDeviceNode The input Text device path node.
  1642. @return A pointer to the newly-created USB Print device path structure.
  1643. **/
  1644. EFI_DEVICE_PATH_PROTOCOL *
  1645. DevPathFromTextUsbPrinter (
  1646. CHAR16 *TextDeviceNode
  1647. )
  1648. {
  1649. USB_CLASS_TEXT UsbClassText;
  1650. UsbClassText.ClassExist = FALSE;
  1651. UsbClassText.Class = USB_CLASS_PRINTER;
  1652. UsbClassText.SubClassExist = TRUE;
  1653. return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
  1654. }
  1655. /**
  1656. Converts a text device path node to USB mass storage device path structure.
  1657. @param TextDeviceNode The input Text device path node.
  1658. @return A pointer to the newly-created USB mass storage device path structure.
  1659. **/
  1660. EFI_DEVICE_PATH_PROTOCOL *
  1661. DevPathFromTextUsbMassStorage (
  1662. CHAR16 *TextDeviceNode
  1663. )
  1664. {
  1665. USB_CLASS_TEXT UsbClassText;
  1666. UsbClassText.ClassExist = FALSE;
  1667. UsbClassText.Class = USB_CLASS_MASS_STORAGE;
  1668. UsbClassText.SubClassExist = TRUE;
  1669. return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
  1670. }
  1671. /**
  1672. Converts a text device path node to USB HUB device path structure.
  1673. @param TextDeviceNode The input Text device path node.
  1674. @return A pointer to the newly-created USB HUB device path structure.
  1675. **/
  1676. EFI_DEVICE_PATH_PROTOCOL *
  1677. DevPathFromTextUsbHub (
  1678. CHAR16 *TextDeviceNode
  1679. )
  1680. {
  1681. USB_CLASS_TEXT UsbClassText;
  1682. UsbClassText.ClassExist = FALSE;
  1683. UsbClassText.Class = USB_CLASS_HUB;
  1684. UsbClassText.SubClassExist = TRUE;
  1685. return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
  1686. }
  1687. /**
  1688. Converts a text device path node to USB CDC data device path structure.
  1689. @param TextDeviceNode The input Text device path node.
  1690. @return A pointer to the newly-created USB CDC data device path structure.
  1691. **/
  1692. EFI_DEVICE_PATH_PROTOCOL *
  1693. DevPathFromTextUsbCDCData (
  1694. CHAR16 *TextDeviceNode
  1695. )
  1696. {
  1697. USB_CLASS_TEXT UsbClassText;
  1698. UsbClassText.ClassExist = FALSE;
  1699. UsbClassText.Class = USB_CLASS_CDCDATA;
  1700. UsbClassText.SubClassExist = TRUE;
  1701. return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
  1702. }
  1703. /**
  1704. Converts a text device path node to USB smart card device path structure.
  1705. @param TextDeviceNode The input Text device path node.
  1706. @return A pointer to the newly-created USB smart card device path structure.
  1707. **/
  1708. EFI_DEVICE_PATH_PROTOCOL *
  1709. DevPathFromTextUsbSmartCard (
  1710. CHAR16 *TextDeviceNode
  1711. )
  1712. {
  1713. USB_CLASS_TEXT UsbClassText;
  1714. UsbClassText.ClassExist = FALSE;
  1715. UsbClassText.Class = USB_CLASS_SMART_CARD;
  1716. UsbClassText.SubClassExist = TRUE;
  1717. return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
  1718. }
  1719. /**
  1720. Converts a text device path node to USB video device path structure.
  1721. @param TextDeviceNode The input Text device path node.
  1722. @return A pointer to the newly-created USB video device path structure.
  1723. **/
  1724. EFI_DEVICE_PATH_PROTOCOL *
  1725. DevPathFromTextUsbVideo (
  1726. CHAR16 *TextDeviceNode
  1727. )
  1728. {
  1729. USB_CLASS_TEXT UsbClassText;
  1730. UsbClassText.ClassExist = FALSE;
  1731. UsbClassText.Class = USB_CLASS_VIDEO;
  1732. UsbClassText.SubClassExist = TRUE;
  1733. return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
  1734. }
  1735. /**
  1736. Converts a text device path node to USB diagnostic device path structure.
  1737. @param TextDeviceNode The input Text device path node.
  1738. @return A pointer to the newly-created USB diagnostic device path structure.
  1739. **/
  1740. EFI_DEVICE_PATH_PROTOCOL *
  1741. DevPathFromTextUsbDiagnostic (
  1742. CHAR16 *TextDeviceNode
  1743. )
  1744. {
  1745. USB_CLASS_TEXT UsbClassText;
  1746. UsbClassText.ClassExist = FALSE;
  1747. UsbClassText.Class = USB_CLASS_DIAGNOSTIC;
  1748. UsbClassText.SubClassExist = TRUE;
  1749. return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
  1750. }
  1751. /**
  1752. Converts a text device path node to USB wireless device path structure.
  1753. @param TextDeviceNode The input Text device path node.
  1754. @return A pointer to the newly-created USB wireless device path structure.
  1755. **/
  1756. EFI_DEVICE_PATH_PROTOCOL *
  1757. DevPathFromTextUsbWireless (
  1758. CHAR16 *TextDeviceNode
  1759. )
  1760. {
  1761. USB_CLASS_TEXT UsbClassText;
  1762. UsbClassText.ClassExist = FALSE;
  1763. UsbClassText.Class = USB_CLASS_WIRELESS;
  1764. UsbClassText.SubClassExist = TRUE;
  1765. return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
  1766. }
  1767. /**
  1768. Converts a text device path node to USB device firmware update device path structure.
  1769. @param TextDeviceNode The input Text device path node.
  1770. @return A pointer to the newly-created USB device firmware update device path structure.
  1771. **/
  1772. EFI_DEVICE_PATH_PROTOCOL *
  1773. DevPathFromTextUsbDeviceFirmwareUpdate (
  1774. CHAR16 *TextDeviceNode
  1775. )
  1776. {
  1777. USB_CLASS_TEXT UsbClassText;
  1778. UsbClassText.ClassExist = FALSE;
  1779. UsbClassText.Class = USB_CLASS_RESERVE;
  1780. UsbClassText.SubClassExist = FALSE;
  1781. UsbClassText.SubClass = USB_SUBCLASS_FW_UPDATE;
  1782. return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
  1783. }
  1784. /**
  1785. Converts a text device path node to USB IRDA bridge device path structure.
  1786. @param TextDeviceNode The input Text device path node.
  1787. @return A pointer to the newly-created USB IRDA bridge device path structure.
  1788. **/
  1789. EFI_DEVICE_PATH_PROTOCOL *
  1790. DevPathFromTextUsbIrdaBridge (
  1791. CHAR16 *TextDeviceNode
  1792. )
  1793. {
  1794. USB_CLASS_TEXT UsbClassText;
  1795. UsbClassText.ClassExist = FALSE;
  1796. UsbClassText.Class = USB_CLASS_RESERVE;
  1797. UsbClassText.SubClassExist = FALSE;
  1798. UsbClassText.SubClass = USB_SUBCLASS_IRDA_BRIDGE;
  1799. return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
  1800. }
  1801. /**
  1802. Converts a text device path node to USB text and measurement device path structure.
  1803. @param TextDeviceNode The input Text device path node.
  1804. @return A pointer to the newly-created USB text and measurement device path structure.
  1805. **/
  1806. EFI_DEVICE_PATH_PROTOCOL *
  1807. DevPathFromTextUsbTestAndMeasurement (
  1808. CHAR16 *TextDeviceNode
  1809. )
  1810. {
  1811. USB_CLASS_TEXT UsbClassText;
  1812. UsbClassText.ClassExist = FALSE;
  1813. UsbClassText.Class = USB_CLASS_RESERVE;
  1814. UsbClassText.SubClassExist = FALSE;
  1815. UsbClassText.SubClass = USB_SUBCLASS_TEST;
  1816. return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
  1817. }
  1818. /**
  1819. Converts a text device path node to USB WWID device path structure.
  1820. @param TextDeviceNode The input Text device path node.
  1821. @return A pointer to the newly-created USB WWID device path structure.
  1822. **/
  1823. EFI_DEVICE_PATH_PROTOCOL *
  1824. DevPathFromTextUsbWwid (
  1825. CHAR16 *TextDeviceNode
  1826. )
  1827. {
  1828. CHAR16 *VIDStr;
  1829. CHAR16 *PIDStr;
  1830. CHAR16 *InterfaceNumStr;
  1831. CHAR16 *SerialNumberStr;
  1832. USB_WWID_DEVICE_PATH *UsbWwid;
  1833. UINTN SerialNumberStrLen;
  1834. VIDStr = GetNextParamStr (&TextDeviceNode);
  1835. PIDStr = GetNextParamStr (&TextDeviceNode);
  1836. InterfaceNumStr = GetNextParamStr (&TextDeviceNode);
  1837. SerialNumberStr = GetNextParamStr (&TextDeviceNode);
  1838. SerialNumberStrLen = StrLen (SerialNumberStr);
  1839. if (SerialNumberStrLen >= 2 &&
  1840. SerialNumberStr[0] == L'\"' &&
  1841. SerialNumberStr[SerialNumberStrLen - 1] == L'\"'
  1842. ) {
  1843. SerialNumberStr[SerialNumberStrLen - 1] = L'\0';
  1844. SerialNumberStr++;
  1845. SerialNumberStrLen -= 2;
  1846. }
  1847. UsbWwid = (USB_WWID_DEVICE_PATH *) CreateDeviceNode (
  1848. MESSAGING_DEVICE_PATH,
  1849. MSG_USB_WWID_DP,
  1850. (UINT16) (sizeof (USB_WWID_DEVICE_PATH) + SerialNumberStrLen * sizeof (CHAR16))
  1851. );
  1852. UsbWwid->VendorId = (UINT16) Strtoi (VIDStr);
  1853. UsbWwid->ProductId = (UINT16) Strtoi (PIDStr);
  1854. UsbWwid->InterfaceNumber = (UINT16) Strtoi (InterfaceNumStr);
  1855. //
  1856. // There is no memory allocated in UsbWwid for the '\0' in SerialNumberStr.
  1857. // Therefore, the '\0' will not be copied.
  1858. //
  1859. memcpy (
  1860. (UINT8 *) UsbWwid + sizeof (USB_WWID_DEVICE_PATH),
  1861. SerialNumberStr,
  1862. SerialNumberStrLen * sizeof (CHAR16)
  1863. );
  1864. return (EFI_DEVICE_PATH_PROTOCOL *) UsbWwid;
  1865. }
  1866. /**
  1867. Converts a text device path node to Logic Unit device path structure.
  1868. @param TextDeviceNode The input Text device path node.
  1869. @return A pointer to the newly-created Logic Unit device path structure.
  1870. **/
  1871. EFI_DEVICE_PATH_PROTOCOL *
  1872. DevPathFromTextUnit (
  1873. CHAR16 *TextDeviceNode
  1874. )
  1875. {
  1876. CHAR16 *LunStr;
  1877. DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;
  1878. LunStr = GetNextParamStr (&TextDeviceNode);
  1879. LogicalUnit = (DEVICE_LOGICAL_UNIT_DEVICE_PATH *) CreateDeviceNode (
  1880. MESSAGING_DEVICE_PATH,
  1881. MSG_DEVICE_LOGICAL_UNIT_DP,
  1882. (UINT16) sizeof (DEVICE_LOGICAL_UNIT_DEVICE_PATH)
  1883. );
  1884. LogicalUnit->Lun = (UINT8) Strtoi (LunStr);
  1885. return (EFI_DEVICE_PATH_PROTOCOL *) LogicalUnit;
  1886. }
  1887. /**
  1888. Converts a text device path node to iSCSI device path structure.
  1889. @param TextDeviceNode The input Text device path node.
  1890. @return A pointer to the newly-created iSCSI device path structure.
  1891. **/
  1892. EFI_DEVICE_PATH_PROTOCOL *
  1893. DevPathFromTextiSCSI (
  1894. CHAR16 *TextDeviceNode
  1895. )
  1896. {
  1897. UINT16 Options;
  1898. CHAR16 *NameStr;
  1899. CHAR16 *PortalGroupStr;
  1900. CHAR16 *LunStr;
  1901. CHAR16 *HeaderDigestStr;
  1902. CHAR16 *DataDigestStr;
  1903. CHAR16 *AuthenticationStr;
  1904. CHAR16 *ProtocolStr;
  1905. CHAR8 *AsciiStr;
  1906. ISCSI_DEVICE_PATH_WITH_NAME *ISCSIDevPath;
  1907. UINT64 Lun;
  1908. NameStr = GetNextParamStr (&TextDeviceNode);
  1909. PortalGroupStr = GetNextParamStr (&TextDeviceNode);
  1910. LunStr = GetNextParamStr (&TextDeviceNode);
  1911. HeaderDigestStr = GetNextParamStr (&TextDeviceNode);
  1912. DataDigestStr = GetNextParamStr (&TextDeviceNode);
  1913. AuthenticationStr = GetNextParamStr (&TextDeviceNode);
  1914. ProtocolStr = GetNextParamStr (&TextDeviceNode);
  1915. ISCSIDevPath = (ISCSI_DEVICE_PATH_WITH_NAME *) CreateDeviceNode (
  1916. MESSAGING_DEVICE_PATH,
  1917. MSG_ISCSI_DP,
  1918. (UINT16) (sizeof (ISCSI_DEVICE_PATH_WITH_NAME) + StrLen (NameStr))
  1919. );
  1920. AsciiStr = ISCSIDevPath->TargetName;
  1921. StrToAscii (NameStr, &AsciiStr);
  1922. ISCSIDevPath->TargetPortalGroupTag = (UINT16) Strtoi (PortalGroupStr);
  1923. Strtoi64 (LunStr, &Lun);
  1924. WriteUnaligned64 ((UINT64 *) &ISCSIDevPath->Lun, SwapBytes64 (Lun));
  1925. Options = 0x0000;
  1926. if (StrCmp (HeaderDigestStr, L"CRC32C") == 0) {
  1927. Options |= 0x0002;
  1928. }
  1929. if (StrCmp (DataDigestStr, L"CRC32C") == 0) {
  1930. Options |= 0x0008;
  1931. }
  1932. if (StrCmp (AuthenticationStr, L"None") == 0) {
  1933. Options |= 0x0800;
  1934. }
  1935. if (StrCmp (AuthenticationStr, L"CHAP_UNI") == 0) {
  1936. Options |= 0x1000;
  1937. }
  1938. ISCSIDevPath->LoginOption = (UINT16) Options;
  1939. if (IS_NULL (*ProtocolStr) || (StrCmp (ProtocolStr, L"TCP") == 0)) {
  1940. ISCSIDevPath->NetworkProtocol = 0;
  1941. } else {
  1942. //
  1943. // Undefined and reserved.
  1944. //
  1945. ISCSIDevPath->NetworkProtocol = 1;
  1946. }
  1947. return (EFI_DEVICE_PATH_PROTOCOL *) ISCSIDevPath;
  1948. }
  1949. /**
  1950. Converts a text device path node to VLAN device path structure.
  1951. @param TextDeviceNode The input Text device path node.
  1952. @return A pointer to the newly-created VLAN device path structure.
  1953. **/
  1954. EFI_DEVICE_PATH_PROTOCOL *
  1955. DevPathFromTextVlan (
  1956. CHAR16 *TextDeviceNode
  1957. )
  1958. {
  1959. CHAR16 *VlanStr;
  1960. VLAN_DEVICE_PATH *Vlan;
  1961. VlanStr = GetNextParamStr (&TextDeviceNode);
  1962. Vlan = (VLAN_DEVICE_PATH *) CreateDeviceNode (
  1963. MESSAGING_DEVICE_PATH,
  1964. MSG_VLAN_DP,
  1965. (UINT16) sizeof (VLAN_DEVICE_PATH)
  1966. );
  1967. Vlan->VlanId = (UINT16) Strtoi (VlanStr);
  1968. return (EFI_DEVICE_PATH_PROTOCOL *) Vlan;
  1969. }
  1970. /**
  1971. Converts a text device path node to Bluetooth device path structure.
  1972. @param TextDeviceNode The input Text device path node.
  1973. @return A pointer to the newly-created Bluetooth device path structure.
  1974. **/
  1975. EFI_DEVICE_PATH_PROTOCOL *
  1976. DevPathFromTextBluetooth (
  1977. CHAR16 *TextDeviceNode
  1978. )
  1979. {
  1980. CHAR16 *BluetoothStr;
  1981. BLUETOOTH_DEVICE_PATH *BluetoothDp;
  1982. BluetoothStr = GetNextParamStr (&TextDeviceNode);
  1983. BluetoothDp = (BLUETOOTH_DEVICE_PATH *) CreateDeviceNode (
  1984. MESSAGING_DEVICE_PATH,
  1985. MSG_BLUETOOTH_DP,
  1986. (UINT16) sizeof (BLUETOOTH_DEVICE_PATH)
  1987. );
  1988. StrHexToBytes (
  1989. BluetoothStr,
  1990. sizeof (BLUETOOTH_ADDRESS) * 2,
  1991. BluetoothDp->BD_ADDR.Address,
  1992. sizeof (BLUETOOTH_ADDRESS)
  1993. );
  1994. return (EFI_DEVICE_PATH_PROTOCOL *) BluetoothDp;
  1995. }
  1996. /**
  1997. Converts a text device path node to Wi-Fi device path structure.
  1998. @param TextDeviceNode The input Text device path node.
  1999. @return A pointer to the newly-created Wi-Fi device path structure.
  2000. **/
  2001. EFI_DEVICE_PATH_PROTOCOL *
  2002. DevPathFromTextWiFi (
  2003. CHAR16 *TextDeviceNode
  2004. )
  2005. {
  2006. CHAR16 *SSIdStr;
  2007. CHAR8 AsciiStr[33];
  2008. UINTN DataLen;
  2009. WIFI_DEVICE_PATH *WiFiDp;
  2010. SSIdStr = GetNextParamStr (&TextDeviceNode);
  2011. WiFiDp = (WIFI_DEVICE_PATH *) CreateDeviceNode (
  2012. MESSAGING_DEVICE_PATH,
  2013. MSG_WIFI_DP,
  2014. (UINT16) sizeof (WIFI_DEVICE_PATH)
  2015. );
  2016. if (NULL != SSIdStr) {
  2017. DataLen = StrLen (SSIdStr);
  2018. if (StrLen (SSIdStr) > 32) {
  2019. SSIdStr[32] = L'\0';
  2020. DataLen = 32;
  2021. }
  2022. UnicodeStrToAsciiStrS (SSIdStr, AsciiStr, sizeof (AsciiStr));
  2023. memcpy (WiFiDp->SSId, AsciiStr, DataLen);
  2024. }
  2025. return (EFI_DEVICE_PATH_PROTOCOL *) WiFiDp;
  2026. }
  2027. /**
  2028. Converts a text device path node to Bluetooth LE device path structure.
  2029. @param TextDeviceNode The input Text device path node.
  2030. @return A pointer to the newly-created Bluetooth LE device path structure.
  2031. **/
  2032. EFI_DEVICE_PATH_PROTOCOL *
  2033. DevPathFromTextBluetoothLE (
  2034. IN CHAR16 *TextDeviceNode
  2035. )
  2036. {
  2037. CHAR16 *BluetoothLeAddrStr;
  2038. CHAR16 *BluetoothLeAddrTypeStr;
  2039. BLUETOOTH_LE_DEVICE_PATH *BluetoothLeDp;
  2040. BluetoothLeAddrStr = GetNextParamStr (&TextDeviceNode);
  2041. BluetoothLeAddrTypeStr = GetNextParamStr (&TextDeviceNode);
  2042. BluetoothLeDp = (BLUETOOTH_LE_DEVICE_PATH *) CreateDeviceNode (
  2043. MESSAGING_DEVICE_PATH,
  2044. MSG_BLUETOOTH_LE_DP,
  2045. (UINT16) sizeof (BLUETOOTH_LE_DEVICE_PATH)
  2046. );
  2047. BluetoothLeDp->Address.Type = (UINT8) Strtoi (BluetoothLeAddrTypeStr);
  2048. StrHexToBytes (
  2049. BluetoothLeAddrStr, sizeof (BluetoothLeDp->Address.Address) * 2,
  2050. BluetoothLeDp->Address.Address, sizeof (BluetoothLeDp->Address.Address)
  2051. );
  2052. return (EFI_DEVICE_PATH_PROTOCOL *) BluetoothLeDp;
  2053. }
  2054. /**
  2055. Converts a text device path node to DNS device path structure.
  2056. @param TextDeviceNode The input Text device path node.
  2057. @return A pointer to the newly-created DNS device path structure.
  2058. **/
  2059. EFI_DEVICE_PATH_PROTOCOL *
  2060. DevPathFromTextDns (
  2061. IN CHAR16 *TextDeviceNode
  2062. )
  2063. {
  2064. CHAR16 *DeviceNodeStr;
  2065. CHAR16 *DeviceNodeStrPtr;
  2066. UINT32 DnsServerIpCount;
  2067. UINT16 DnsDeviceNodeLength;
  2068. DNS_DEVICE_PATH *DnsDeviceNode;
  2069. UINT32 DnsServerIpIndex;
  2070. CHAR16 *DnsServerIp;
  2071. //
  2072. // Count the DNS server address number.
  2073. //
  2074. DeviceNodeStr = UefiDevicePathLibStrDuplicate (TextDeviceNode);
  2075. if (DeviceNodeStr == NULL) {
  2076. return NULL;
  2077. }
  2078. DeviceNodeStrPtr = DeviceNodeStr;
  2079. DnsServerIpCount = 0;
  2080. while (DeviceNodeStrPtr != NULL && *DeviceNodeStrPtr != L'\0') {
  2081. GetNextParamStr (&DeviceNodeStrPtr);
  2082. DnsServerIpCount ++;
  2083. }
  2084. free (DeviceNodeStr);
  2085. DeviceNodeStr = NULL;
  2086. //
  2087. // One or more instances of the DNS server address in EFI_IP_ADDRESS,
  2088. // otherwise, NULL will be returned.
  2089. //
  2090. if (DnsServerIpCount == 0) {
  2091. return NULL;
  2092. }
  2093. //
  2094. // Create the DNS DeviceNode.
  2095. //
  2096. DnsDeviceNodeLength = (UINT16) (sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof (UINT8) + DnsServerIpCount * sizeof (EFI_IP_ADDRESS));
  2097. DnsDeviceNode = (DNS_DEVICE_PATH *) CreateDeviceNode (
  2098. MESSAGING_DEVICE_PATH,
  2099. MSG_DNS_DP,
  2100. DnsDeviceNodeLength
  2101. );
  2102. if (DnsDeviceNode == NULL) {
  2103. return NULL;
  2104. }
  2105. //
  2106. // Confirm the DNS server address is IPv4 or IPv6 type.
  2107. //
  2108. DeviceNodeStrPtr = TextDeviceNode;
  2109. while (!IS_NULL (*DeviceNodeStrPtr)) {
  2110. if (*DeviceNodeStrPtr == L'.') {
  2111. DnsDeviceNode->IsIPv6 = 0x00;
  2112. break;
  2113. }
  2114. if (*DeviceNodeStrPtr == L':') {
  2115. DnsDeviceNode->IsIPv6 = 0x01;
  2116. break;
  2117. }
  2118. DeviceNodeStrPtr++;
  2119. }
  2120. for (DnsServerIpIndex = 0; DnsServerIpIndex < DnsServerIpCount; DnsServerIpIndex++) {
  2121. DnsServerIp = GetNextParamStr (&TextDeviceNode);
  2122. if (DnsDeviceNode->IsIPv6 == 0x00) {
  2123. StrToIpv4Address (DnsServerIp, NULL, &(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v4), NULL);
  2124. } else {
  2125. StrToIpv6Address (DnsServerIp, NULL, &(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v6), NULL);
  2126. }
  2127. }
  2128. return (EFI_DEVICE_PATH_PROTOCOL *) DnsDeviceNode;
  2129. }
  2130. /**
  2131. Converts a text device path node to URI device path structure.
  2132. @param TextDeviceNode The input Text device path node.
  2133. @return A pointer to the newly-created URI device path structure.
  2134. **/
  2135. EFI_DEVICE_PATH_PROTOCOL *
  2136. DevPathFromTextUri (
  2137. CHAR16 *TextDeviceNode
  2138. )
  2139. {
  2140. CHAR16 *UriStr;
  2141. UINTN UriLength;
  2142. URI_DEVICE_PATH *Uri;
  2143. UriStr = GetNextParamStr (&TextDeviceNode);
  2144. UriLength = StrnLenS (UriStr, MAX_UINT16 - sizeof (URI_DEVICE_PATH));
  2145. Uri = (URI_DEVICE_PATH *) CreateDeviceNode (
  2146. MESSAGING_DEVICE_PATH,
  2147. MSG_URI_DP,
  2148. (UINT16) (sizeof (URI_DEVICE_PATH) + UriLength)
  2149. );
  2150. while (UriLength-- != 0) {
  2151. Uri->Uri[UriLength] = (CHAR8) UriStr[UriLength];
  2152. }
  2153. return (EFI_DEVICE_PATH_PROTOCOL *) Uri;
  2154. }
  2155. /**
  2156. Converts a media text device path node to media device path structure.
  2157. @param TextDeviceNode The input Text device path node.
  2158. @return A pointer to media device path structure.
  2159. **/
  2160. EFI_DEVICE_PATH_PROTOCOL *
  2161. DevPathFromTextMediaPath (
  2162. CHAR16 *TextDeviceNode
  2163. )
  2164. {
  2165. return DevPathFromTextGenericPath (MEDIA_DEVICE_PATH, TextDeviceNode);
  2166. }
  2167. /**
  2168. Converts a text device path node to HD device path structure.
  2169. @param TextDeviceNode The input Text device path node.
  2170. @return A pointer to the newly-created HD device path structure.
  2171. **/
  2172. EFI_DEVICE_PATH_PROTOCOL *
  2173. DevPathFromTextHD (
  2174. CHAR16 *TextDeviceNode
  2175. )
  2176. {
  2177. CHAR16 *PartitionStr;
  2178. CHAR16 *TypeStr;
  2179. CHAR16 *SignatureStr;
  2180. CHAR16 *StartStr;
  2181. CHAR16 *SizeStr;
  2182. UINT32 Signature32;
  2183. HARDDRIVE_DEVICE_PATH *Hd;
  2184. PartitionStr = GetNextParamStr (&TextDeviceNode);
  2185. TypeStr = GetNextParamStr (&TextDeviceNode);
  2186. SignatureStr = GetNextParamStr (&TextDeviceNode);
  2187. StartStr = GetNextParamStr (&TextDeviceNode);
  2188. SizeStr = GetNextParamStr (&TextDeviceNode);
  2189. Hd = (HARDDRIVE_DEVICE_PATH *) CreateDeviceNode (
  2190. MEDIA_DEVICE_PATH,
  2191. MEDIA_HARDDRIVE_DP,
  2192. (UINT16) sizeof (HARDDRIVE_DEVICE_PATH)
  2193. );
  2194. Hd->PartitionNumber = (UINT32) Strtoi (PartitionStr);
  2195. ZeroMem (Hd->Signature, 16);
  2196. Hd->MBRType = (UINT8) 0;
  2197. if (StrCmp (TypeStr, L"MBR") == 0) {
  2198. Hd->SignatureType = SIGNATURE_TYPE_MBR;
  2199. Hd->MBRType = 0x01;
  2200. Signature32 = (UINT32) Strtoi (SignatureStr);
  2201. memcpy (Hd->Signature, &Signature32, sizeof (UINT32));
  2202. } else if (StrCmp (TypeStr, L"GPT") == 0) {
  2203. Hd->SignatureType = SIGNATURE_TYPE_GUID;
  2204. Hd->MBRType = 0x02;
  2205. StrToGuid (SignatureStr, (EFI_GUID *) Hd->Signature);
  2206. } else {
  2207. Hd->SignatureType = (UINT8) Strtoi (TypeStr);
  2208. }
  2209. Strtoi64 (StartStr, &Hd->PartitionStart);
  2210. Strtoi64 (SizeStr, &Hd->PartitionSize);
  2211. return (EFI_DEVICE_PATH_PROTOCOL *) Hd;
  2212. }
  2213. /**
  2214. Converts a text device path node to CDROM device path structure.
  2215. @param TextDeviceNode The input Text device path node.
  2216. @return A pointer to the newly-created CDROM device path structure.
  2217. **/
  2218. EFI_DEVICE_PATH_PROTOCOL *
  2219. DevPathFromTextCDROM (
  2220. CHAR16 *TextDeviceNode
  2221. )
  2222. {
  2223. CHAR16 *EntryStr;
  2224. CHAR16 *StartStr;
  2225. CHAR16 *SizeStr;
  2226. CDROM_DEVICE_PATH *CDROMDevPath;
  2227. EntryStr = GetNextParamStr (&TextDeviceNode);
  2228. StartStr = GetNextParamStr (&TextDeviceNode);
  2229. SizeStr = GetNextParamStr (&TextDeviceNode);
  2230. CDROMDevPath = (CDROM_DEVICE_PATH *) CreateDeviceNode (
  2231. MEDIA_DEVICE_PATH,
  2232. MEDIA_CDROM_DP,
  2233. (UINT16) sizeof (CDROM_DEVICE_PATH)
  2234. );
  2235. CDROMDevPath->BootEntry = (UINT32) Strtoi (EntryStr);
  2236. Strtoi64 (StartStr, &CDROMDevPath->PartitionStart);
  2237. Strtoi64 (SizeStr, &CDROMDevPath->PartitionSize);
  2238. return (EFI_DEVICE_PATH_PROTOCOL *) CDROMDevPath;
  2239. }
  2240. /**
  2241. Converts a text device path node to Vendor-defined media device path structure.
  2242. @param TextDeviceNode The input Text device path node.
  2243. @return A pointer to the newly-created Vendor-defined media device path structure.
  2244. **/
  2245. EFI_DEVICE_PATH_PROTOCOL *
  2246. DevPathFromTextVenMedia (
  2247. CHAR16 *TextDeviceNode
  2248. )
  2249. {
  2250. return ConvertFromTextVendor (
  2251. TextDeviceNode,
  2252. MEDIA_DEVICE_PATH,
  2253. MEDIA_VENDOR_DP
  2254. );
  2255. }
  2256. /**
  2257. Converts a text device path node to File device path structure.
  2258. @param TextDeviceNode The input Text device path node.
  2259. @return A pointer to the newly-created File device path structure.
  2260. **/
  2261. EFI_DEVICE_PATH_PROTOCOL *
  2262. DevPathFromTextFilePath (
  2263. CHAR16 *TextDeviceNode
  2264. )
  2265. {
  2266. FILEPATH_DEVICE_PATH *File;
  2267. File = (FILEPATH_DEVICE_PATH *) CreateDeviceNode (
  2268. MEDIA_DEVICE_PATH,
  2269. MEDIA_FILEPATH_DP,
  2270. (UINT16) (sizeof (FILEPATH_DEVICE_PATH) + StrLen (TextDeviceNode) * 2)
  2271. );
  2272. StrCpyS (File->PathName, StrLen (TextDeviceNode) + 1, TextDeviceNode);
  2273. return (EFI_DEVICE_PATH_PROTOCOL *) File;
  2274. }
  2275. /**
  2276. Converts a text device path node to Media protocol device path structure.
  2277. @param TextDeviceNode The input Text device path node.
  2278. @return A pointer to the newly-created Media protocol device path structure.
  2279. **/
  2280. EFI_DEVICE_PATH_PROTOCOL *
  2281. DevPathFromTextMedia (
  2282. CHAR16 *TextDeviceNode
  2283. )
  2284. {
  2285. CHAR16 *GuidStr;
  2286. MEDIA_PROTOCOL_DEVICE_PATH *Media;
  2287. GuidStr = GetNextParamStr (&TextDeviceNode);
  2288. Media = (MEDIA_PROTOCOL_DEVICE_PATH *) CreateDeviceNode (
  2289. MEDIA_DEVICE_PATH,
  2290. MEDIA_PROTOCOL_DP,
  2291. (UINT16) sizeof (MEDIA_PROTOCOL_DEVICE_PATH)
  2292. );
  2293. StrToGuid (GuidStr, &Media->Protocol);
  2294. return (EFI_DEVICE_PATH_PROTOCOL *) Media;
  2295. }
  2296. /**
  2297. Converts a text device path node to firmware volume device path structure.
  2298. @param TextDeviceNode The input Text device path node.
  2299. @return A pointer to the newly-created firmware volume device path structure.
  2300. **/
  2301. EFI_DEVICE_PATH_PROTOCOL *
  2302. DevPathFromTextFv (
  2303. CHAR16 *TextDeviceNode
  2304. )
  2305. {
  2306. CHAR16 *GuidStr;
  2307. MEDIA_FW_VOL_DEVICE_PATH *Fv;
  2308. GuidStr = GetNextParamStr (&TextDeviceNode);
  2309. Fv = (MEDIA_FW_VOL_DEVICE_PATH *) CreateDeviceNode (
  2310. MEDIA_DEVICE_PATH,
  2311. MEDIA_PIWG_FW_VOL_DP,
  2312. (UINT16) sizeof (MEDIA_FW_VOL_DEVICE_PATH)
  2313. );
  2314. StrToGuid (GuidStr, &Fv->FvName);
  2315. return (EFI_DEVICE_PATH_PROTOCOL *) Fv;
  2316. }
  2317. /**
  2318. Converts a text device path node to firmware file device path structure.
  2319. @param TextDeviceNode The input Text device path node.
  2320. @return A pointer to the newly-created firmware file device path structure.
  2321. **/
  2322. EFI_DEVICE_PATH_PROTOCOL *
  2323. DevPathFromTextFvFile (
  2324. CHAR16 *TextDeviceNode
  2325. )
  2326. {
  2327. CHAR16 *GuidStr;
  2328. MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFile;
  2329. GuidStr = GetNextParamStr (&TextDeviceNode);
  2330. FvFile = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) CreateDeviceNode (
  2331. MEDIA_DEVICE_PATH,
  2332. MEDIA_PIWG_FW_FILE_DP,
  2333. (UINT16) sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH)
  2334. );
  2335. StrToGuid (GuidStr, &FvFile->FvFileName);
  2336. return (EFI_DEVICE_PATH_PROTOCOL *) FvFile;
  2337. }
  2338. /**
  2339. Converts a text device path node to text relative offset device path structure.
  2340. @param TextDeviceNode The input Text device path node.
  2341. @return A pointer to the newly-created Text device path structure.
  2342. **/
  2343. EFI_DEVICE_PATH_PROTOCOL *
  2344. DevPathFromTextRelativeOffsetRange (
  2345. CHAR16 *TextDeviceNode
  2346. )
  2347. {
  2348. CHAR16 *StartingOffsetStr;
  2349. CHAR16 *EndingOffsetStr;
  2350. MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *Offset;
  2351. StartingOffsetStr = GetNextParamStr (&TextDeviceNode);
  2352. EndingOffsetStr = GetNextParamStr (&TextDeviceNode);
  2353. Offset = (MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *) CreateDeviceNode (
  2354. MEDIA_DEVICE_PATH,
  2355. MEDIA_RELATIVE_OFFSET_RANGE_DP,
  2356. (UINT16) sizeof (MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH)
  2357. );
  2358. Strtoi64 (StartingOffsetStr, &Offset->StartingOffset);
  2359. Strtoi64 (EndingOffsetStr, &Offset->EndingOffset);
  2360. return (EFI_DEVICE_PATH_PROTOCOL *) Offset;
  2361. }
  2362. /**
  2363. Converts a text device path node to text ram disk device path structure.
  2364. @param TextDeviceNode The input Text device path node.
  2365. @return A pointer to the newly-created Text device path structure.
  2366. **/
  2367. EFI_DEVICE_PATH_PROTOCOL *
  2368. DevPathFromTextRamDisk (
  2369. CHAR16 *TextDeviceNode
  2370. )
  2371. {
  2372. CHAR16 *StartingAddrStr;
  2373. CHAR16 *EndingAddrStr;
  2374. CHAR16 *TypeGuidStr;
  2375. CHAR16 *InstanceStr;
  2376. MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;
  2377. UINT64 StartingAddr;
  2378. UINT64 EndingAddr;
  2379. StartingAddrStr = GetNextParamStr (&TextDeviceNode);
  2380. EndingAddrStr = GetNextParamStr (&TextDeviceNode);
  2381. InstanceStr = GetNextParamStr (&TextDeviceNode);
  2382. TypeGuidStr = GetNextParamStr (&TextDeviceNode);
  2383. RamDisk = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (
  2384. MEDIA_DEVICE_PATH,
  2385. MEDIA_RAM_DISK_DP,
  2386. (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
  2387. );
  2388. Strtoi64 (StartingAddrStr, &StartingAddr);
  2389. WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);
  2390. Strtoi64 (EndingAddrStr, &EndingAddr);
  2391. WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);
  2392. RamDisk->Instance = (UINT16) Strtoi (InstanceStr);
  2393. StrToGuid (TypeGuidStr, &RamDisk->TypeGuid);
  2394. return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;
  2395. }
  2396. /**
  2397. Converts a text device path node to text virtual disk device path structure.
  2398. @param TextDeviceNode The input Text device path node.
  2399. @return A pointer to the newly-created Text device path structure.
  2400. **/
  2401. EFI_DEVICE_PATH_PROTOCOL *
  2402. DevPathFromTextVirtualDisk (
  2403. CHAR16 *TextDeviceNode
  2404. )
  2405. {
  2406. CHAR16 *StartingAddrStr;
  2407. CHAR16 *EndingAddrStr;
  2408. CHAR16 *InstanceStr;
  2409. MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;
  2410. UINT64 StartingAddr;
  2411. UINT64 EndingAddr;
  2412. StartingAddrStr = GetNextParamStr (&TextDeviceNode);
  2413. EndingAddrStr = GetNextParamStr (&TextDeviceNode);
  2414. InstanceStr = GetNextParamStr (&TextDeviceNode);
  2415. RamDisk = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (
  2416. MEDIA_DEVICE_PATH,
  2417. MEDIA_RAM_DISK_DP,
  2418. (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
  2419. );
  2420. Strtoi64 (StartingAddrStr, &StartingAddr);
  2421. WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);
  2422. Strtoi64 (EndingAddrStr, &EndingAddr);
  2423. WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);
  2424. RamDisk->Instance = (UINT16) Strtoi (InstanceStr);
  2425. CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualDiskGuid);
  2426. return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;
  2427. }
  2428. /**
  2429. Converts a text device path node to text virtual cd device path structure.
  2430. @param TextDeviceNode The input Text device path node.
  2431. @return A pointer to the newly-created Text device path structure.
  2432. **/
  2433. EFI_DEVICE_PATH_PROTOCOL *
  2434. DevPathFromTextVirtualCd (
  2435. CHAR16 *TextDeviceNode
  2436. )
  2437. {
  2438. CHAR16 *StartingAddrStr;
  2439. CHAR16 *EndingAddrStr;
  2440. CHAR16 *InstanceStr;
  2441. MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;
  2442. UINT64 StartingAddr;
  2443. UINT64 EndingAddr;
  2444. StartingAddrStr = GetNextParamStr (&TextDeviceNode);
  2445. EndingAddrStr = GetNextParamStr (&TextDeviceNode);
  2446. InstanceStr = GetNextParamStr (&TextDeviceNode);
  2447. RamDisk = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (
  2448. MEDIA_DEVICE_PATH,
  2449. MEDIA_RAM_DISK_DP,
  2450. (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
  2451. );
  2452. Strtoi64 (StartingAddrStr, &StartingAddr);
  2453. WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);
  2454. Strtoi64 (EndingAddrStr, &EndingAddr);
  2455. WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);
  2456. RamDisk->Instance = (UINT16) Strtoi (InstanceStr);
  2457. CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualCdGuid);
  2458. return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;
  2459. }
  2460. /**
  2461. Converts a text device path node to text persistent virtual disk device path structure.
  2462. @param TextDeviceNode The input Text device path node.
  2463. @return A pointer to the newly-created Text device path structure.
  2464. **/
  2465. EFI_DEVICE_PATH_PROTOCOL *
  2466. DevPathFromTextPersistentVirtualDisk (
  2467. CHAR16 *TextDeviceNode
  2468. )
  2469. {
  2470. CHAR16 *StartingAddrStr;
  2471. CHAR16 *EndingAddrStr;
  2472. CHAR16 *InstanceStr;
  2473. MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;
  2474. UINT64 StartingAddr;
  2475. UINT64 EndingAddr;
  2476. StartingAddrStr = GetNextParamStr (&TextDeviceNode);
  2477. EndingAddrStr = GetNextParamStr (&TextDeviceNode);
  2478. InstanceStr = GetNextParamStr (&TextDeviceNode);
  2479. RamDisk = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (
  2480. MEDIA_DEVICE_PATH,
  2481. MEDIA_RAM_DISK_DP,
  2482. (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
  2483. );
  2484. Strtoi64 (StartingAddrStr, &StartingAddr);
  2485. WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);
  2486. Strtoi64 (EndingAddrStr, &EndingAddr);
  2487. WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);
  2488. RamDisk->Instance = (UINT16) Strtoi (InstanceStr);
  2489. CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualDiskGuid);
  2490. return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;
  2491. }
  2492. /**
  2493. Converts a text device path node to text persistent virtual cd device path structure.
  2494. @param TextDeviceNode The input Text device path node.
  2495. @return A pointer to the newly-created Text device path structure.
  2496. **/
  2497. EFI_DEVICE_PATH_PROTOCOL *
  2498. DevPathFromTextPersistentVirtualCd (
  2499. CHAR16 *TextDeviceNode
  2500. )
  2501. {
  2502. CHAR16 *StartingAddrStr;
  2503. CHAR16 *EndingAddrStr;
  2504. CHAR16 *InstanceStr;
  2505. MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;
  2506. UINT64 StartingAddr;
  2507. UINT64 EndingAddr;
  2508. StartingAddrStr = GetNextParamStr (&TextDeviceNode);
  2509. EndingAddrStr = GetNextParamStr (&TextDeviceNode);
  2510. InstanceStr = GetNextParamStr (&TextDeviceNode);
  2511. RamDisk = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (
  2512. MEDIA_DEVICE_PATH,
  2513. MEDIA_RAM_DISK_DP,
  2514. (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
  2515. );
  2516. Strtoi64 (StartingAddrStr, &StartingAddr);
  2517. WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);
  2518. Strtoi64 (EndingAddrStr, &EndingAddr);
  2519. WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);
  2520. RamDisk->Instance = (UINT16) Strtoi (InstanceStr);
  2521. CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualCdGuid);
  2522. return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;
  2523. }
  2524. /**
  2525. Converts a BBS text device path node to BBS device path structure.
  2526. @param TextDeviceNode The input Text device path node.
  2527. @return A pointer to BBS device path structure.
  2528. **/
  2529. EFI_DEVICE_PATH_PROTOCOL *
  2530. DevPathFromTextBbsPath (
  2531. CHAR16 *TextDeviceNode
  2532. )
  2533. {
  2534. return DevPathFromTextGenericPath (BBS_DEVICE_PATH, TextDeviceNode);
  2535. }
  2536. /**
  2537. Converts a text device path node to BIOS Boot Specification device path structure.
  2538. @param TextDeviceNode The input Text device path node.
  2539. @return A pointer to the newly-created BIOS Boot Specification device path structure.
  2540. **/
  2541. EFI_DEVICE_PATH_PROTOCOL *
  2542. DevPathFromTextBBS (
  2543. CHAR16 *TextDeviceNode
  2544. )
  2545. {
  2546. CHAR16 *TypeStr;
  2547. CHAR16 *IdStr;
  2548. CHAR16 *FlagsStr;
  2549. CHAR8 *AsciiStr;
  2550. BBS_BBS_DEVICE_PATH *Bbs;
  2551. TypeStr = GetNextParamStr (&TextDeviceNode);
  2552. IdStr = GetNextParamStr (&TextDeviceNode);
  2553. FlagsStr = GetNextParamStr (&TextDeviceNode);
  2554. Bbs = (BBS_BBS_DEVICE_PATH *) CreateDeviceNode (
  2555. BBS_DEVICE_PATH,
  2556. BBS_BBS_DP,
  2557. (UINT16) (sizeof (BBS_BBS_DEVICE_PATH) + StrLen (IdStr))
  2558. );
  2559. if (StrCmp (TypeStr, L"Floppy") == 0) {
  2560. Bbs->DeviceType = BBS_TYPE_FLOPPY;
  2561. } else if (StrCmp (TypeStr, L"HD") == 0) {
  2562. Bbs->DeviceType = BBS_TYPE_HARDDRIVE;
  2563. } else if (StrCmp (TypeStr, L"CDROM") == 0) {
  2564. Bbs->DeviceType = BBS_TYPE_CDROM;
  2565. } else if (StrCmp (TypeStr, L"PCMCIA") == 0) {
  2566. Bbs->DeviceType = BBS_TYPE_PCMCIA;
  2567. } else if (StrCmp (TypeStr, L"USB") == 0) {
  2568. Bbs->DeviceType = BBS_TYPE_USB;
  2569. } else if (StrCmp (TypeStr, L"Network") == 0) {
  2570. Bbs->DeviceType = BBS_TYPE_EMBEDDED_NETWORK;
  2571. } else {
  2572. Bbs->DeviceType = (UINT16) Strtoi (TypeStr);
  2573. }
  2574. AsciiStr = Bbs->String;
  2575. StrToAscii (IdStr, &AsciiStr);
  2576. Bbs->StatusFlag = (UINT16) Strtoi (FlagsStr);
  2577. return (EFI_DEVICE_PATH_PROTOCOL *) Bbs;
  2578. }
  2579. /**
  2580. Converts a text device path node to SATA device path structure.
  2581. @param TextDeviceNode The input Text device path node.
  2582. @return A pointer to the newly-created SATA device path structure.
  2583. **/
  2584. EFI_DEVICE_PATH_PROTOCOL *
  2585. DevPathFromTextSata (
  2586. CHAR16 *TextDeviceNode
  2587. )
  2588. {
  2589. SATA_DEVICE_PATH *Sata;
  2590. CHAR16 *Param1;
  2591. CHAR16 *Param2;
  2592. CHAR16 *Param3;
  2593. Param1 = GetNextParamStr (&TextDeviceNode);
  2594. Param2 = GetNextParamStr (&TextDeviceNode);
  2595. Param3 = GetNextParamStr (&TextDeviceNode);
  2596. Sata = (SATA_DEVICE_PATH *) CreateDeviceNode (
  2597. MESSAGING_DEVICE_PATH,
  2598. MSG_SATA_DP,
  2599. (UINT16) sizeof (SATA_DEVICE_PATH)
  2600. );
  2601. Sata->HBAPortNumber = (UINT16) Strtoi (Param1);
  2602. //
  2603. // According to UEFI spec, if PMPN is not provided, the default is 0xFFFF
  2604. //
  2605. if (*Param2 == L'\0' ) {
  2606. Sata->PortMultiplierPortNumber = 0xFFFF;
  2607. } else {
  2608. Sata->PortMultiplierPortNumber = (UINT16) Strtoi (Param2);
  2609. }
  2610. Sata->Lun = (UINT16) Strtoi (Param3);
  2611. return (EFI_DEVICE_PATH_PROTOCOL *) Sata;
  2612. }
  2613. DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevPathFromTextTable[] = {
  2614. {L"Path", DevPathFromTextPath },
  2615. {L"HardwarePath", DevPathFromTextHardwarePath },
  2616. {L"Pci", DevPathFromTextPci },
  2617. {L"PcCard", DevPathFromTextPcCard },
  2618. {L"MemoryMapped", DevPathFromTextMemoryMapped },
  2619. {L"VenHw", DevPathFromTextVenHw },
  2620. {L"Ctrl", DevPathFromTextCtrl },
  2621. {L"BMC", DevPathFromTextBmc },
  2622. {L"AcpiPath", DevPathFromTextAcpiPath },
  2623. {L"Acpi", DevPathFromTextAcpi },
  2624. {L"PciRoot", DevPathFromTextPciRoot },
  2625. {L"PcieRoot", DevPathFromTextPcieRoot },
  2626. {L"Floppy", DevPathFromTextFloppy },
  2627. {L"Keyboard", DevPathFromTextKeyboard },
  2628. {L"Serial", DevPathFromTextSerial },
  2629. {L"ParallelPort", DevPathFromTextParallelPort },
  2630. {L"AcpiEx", DevPathFromTextAcpiEx },
  2631. {L"AcpiExp", DevPathFromTextAcpiExp },
  2632. {L"AcpiAdr", DevPathFromTextAcpiAdr },
  2633. {L"Msg", DevPathFromTextMsg },
  2634. {L"Ata", DevPathFromTextAta },
  2635. {L"Scsi", DevPathFromTextScsi },
  2636. {L"Fibre", DevPathFromTextFibre },
  2637. {L"FibreEx", DevPathFromTextFibreEx },
  2638. {L"I1394", DevPathFromText1394 },
  2639. {L"USB", DevPathFromTextUsb },
  2640. {L"I2O", DevPathFromTextI2O },
  2641. {L"Infiniband", DevPathFromTextInfiniband },
  2642. {L"VenMsg", DevPathFromTextVenMsg },
  2643. {L"VenPcAnsi", DevPathFromTextVenPcAnsi },
  2644. {L"VenVt100", DevPathFromTextVenVt100 },
  2645. {L"VenVt100Plus", DevPathFromTextVenVt100Plus },
  2646. {L"VenUtf8", DevPathFromTextVenUtf8 },
  2647. {L"UartFlowCtrl", DevPathFromTextUartFlowCtrl },
  2648. {L"SAS", DevPathFromTextSAS },
  2649. {L"SasEx", DevPathFromTextSasEx },
  2650. {L"NVMe", DevPathFromTextNVMe },
  2651. {L"UFS", DevPathFromTextUfs },
  2652. {L"SD", DevPathFromTextSd },
  2653. {L"eMMC", DevPathFromTextEmmc },
  2654. {L"DebugPort", DevPathFromTextDebugPort },
  2655. {L"MAC", DevPathFromTextMAC },
  2656. {L"IPv4", DevPathFromTextIPv4 },
  2657. {L"IPv6", DevPathFromTextIPv6 },
  2658. {L"Uart", DevPathFromTextUart },
  2659. {L"UsbClass", DevPathFromTextUsbClass },
  2660. {L"UsbAudio", DevPathFromTextUsbAudio },
  2661. {L"UsbCDCControl", DevPathFromTextUsbCDCControl },
  2662. {L"UsbHID", DevPathFromTextUsbHID },
  2663. {L"UsbImage", DevPathFromTextUsbImage },
  2664. {L"UsbPrinter", DevPathFromTextUsbPrinter },
  2665. {L"UsbMassStorage", DevPathFromTextUsbMassStorage },
  2666. {L"UsbHub", DevPathFromTextUsbHub },
  2667. {L"UsbCDCData", DevPathFromTextUsbCDCData },
  2668. {L"UsbSmartCard", DevPathFromTextUsbSmartCard },
  2669. {L"UsbVideo", DevPathFromTextUsbVideo },
  2670. {L"UsbDiagnostic", DevPathFromTextUsbDiagnostic },
  2671. {L"UsbWireless", DevPathFromTextUsbWireless },
  2672. {L"UsbDeviceFirmwareUpdate", DevPathFromTextUsbDeviceFirmwareUpdate },
  2673. {L"UsbIrdaBridge", DevPathFromTextUsbIrdaBridge },
  2674. {L"UsbTestAndMeasurement", DevPathFromTextUsbTestAndMeasurement },
  2675. {L"UsbWwid", DevPathFromTextUsbWwid },
  2676. {L"Unit", DevPathFromTextUnit },
  2677. {L"iSCSI", DevPathFromTextiSCSI },
  2678. {L"Vlan", DevPathFromTextVlan },
  2679. {L"Dns", DevPathFromTextDns },
  2680. {L"Uri", DevPathFromTextUri },
  2681. {L"Bluetooth", DevPathFromTextBluetooth },
  2682. {L"Wi-Fi", DevPathFromTextWiFi },
  2683. {L"BluetoothLE", DevPathFromTextBluetoothLE },
  2684. {L"MediaPath", DevPathFromTextMediaPath },
  2685. {L"HD", DevPathFromTextHD },
  2686. {L"CDROM", DevPathFromTextCDROM },
  2687. {L"VenMedia", DevPathFromTextVenMedia },
  2688. {L"Media", DevPathFromTextMedia },
  2689. {L"Fv", DevPathFromTextFv },
  2690. {L"FvFile", DevPathFromTextFvFile },
  2691. {L"Offset", DevPathFromTextRelativeOffsetRange },
  2692. {L"RamDisk", DevPathFromTextRamDisk },
  2693. {L"VirtualDisk", DevPathFromTextVirtualDisk },
  2694. {L"VirtualCD", DevPathFromTextVirtualCd },
  2695. {L"PersistentVirtualDisk", DevPathFromTextPersistentVirtualDisk },
  2696. {L"PersistentVirtualCD", DevPathFromTextPersistentVirtualCd },
  2697. {L"BbsPath", DevPathFromTextBbsPath },
  2698. {L"BBS", DevPathFromTextBBS },
  2699. {L"Sata", DevPathFromTextSata },
  2700. {NULL, NULL}
  2701. };
  2702. /**
  2703. Convert text to the binary representation of a device node.
  2704. @param TextDeviceNode TextDeviceNode points to the text representation of a device
  2705. node. Conversion starts with the first character and continues
  2706. until the first non-device node character.
  2707. @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
  2708. insufficient memory or text unsupported.
  2709. **/
  2710. EFI_DEVICE_PATH_PROTOCOL *
  2711. UefiDevicePathLibConvertTextToDeviceNode (
  2712. CONST CHAR16 *TextDeviceNode
  2713. )
  2714. {
  2715. DEVICE_PATH_FROM_TEXT FromText;
  2716. CHAR16 *ParamStr;
  2717. EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
  2718. CHAR16 *DeviceNodeStr;
  2719. UINTN Index;
  2720. if ((TextDeviceNode == NULL) || (IS_NULL (*TextDeviceNode))) {
  2721. return NULL;
  2722. }
  2723. ParamStr = NULL;
  2724. FromText = NULL;
  2725. DeviceNodeStr = UefiDevicePathLibStrDuplicate (TextDeviceNode);
  2726. ASSERT (DeviceNodeStr != NULL);
  2727. for (Index = 0; mUefiDevicePathLibDevPathFromTextTable[Index].Function != NULL; Index++) {
  2728. ParamStr = GetParamByNodeName (DeviceNodeStr, mUefiDevicePathLibDevPathFromTextTable[Index].DevicePathNodeText);
  2729. if (ParamStr != NULL) {
  2730. FromText = mUefiDevicePathLibDevPathFromTextTable[Index].Function;
  2731. break;
  2732. }
  2733. }
  2734. if (FromText == NULL) {
  2735. //
  2736. // A file path
  2737. //
  2738. FromText = DevPathFromTextFilePath;
  2739. DeviceNode = FromText (DeviceNodeStr);
  2740. //
  2741. // According to above logic, if 'FromText' is NULL in the 'if' statement,
  2742. // then 'ParamStr' must be NULL as well. No memory allocation has been made
  2743. // in this case.
  2744. //
  2745. // The below check is for addressing a false positive potential memory leak
  2746. // issue raised from static analysis.
  2747. //
  2748. if (ParamStr != NULL) {
  2749. free (ParamStr);
  2750. }
  2751. } else {
  2752. DeviceNode = FromText (ParamStr);
  2753. free (ParamStr);
  2754. }
  2755. free (DeviceNodeStr);
  2756. return DeviceNode;
  2757. }
  2758. /**
  2759. Convert text to the binary representation of a device path.
  2760. @param TextDevicePath TextDevicePath points to the text representation of a device
  2761. path. Conversion starts with the first character and continues
  2762. until the first non-device node character.
  2763. @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
  2764. there was insufficient memory.
  2765. **/
  2766. EFI_DEVICE_PATH_PROTOCOL *
  2767. UefiDevicePathLibConvertTextToDevicePath (
  2768. CONST CHAR16 *TextDevicePath
  2769. )
  2770. {
  2771. EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
  2772. EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
  2773. CHAR16 *DevicePathStr;
  2774. CHAR16 *Str;
  2775. CHAR16 *DeviceNodeStr;
  2776. BOOLEAN IsInstanceEnd;
  2777. EFI_DEVICE_PATH_PROTOCOL *DevicePath;
  2778. if ((TextDevicePath == NULL) || (IS_NULL (*TextDevicePath))) {
  2779. return NULL;
  2780. }
  2781. DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);
  2782. ASSERT (DevicePath != NULL);
  2783. SetDevicePathEndNode (DevicePath);
  2784. DevicePathStr = UefiDevicePathLibStrDuplicate (TextDevicePath);
  2785. Str = DevicePathStr;
  2786. while ((DeviceNodeStr = GetNextDeviceNodeStr (&Str, &IsInstanceEnd)) != NULL) {
  2787. DeviceNode = UefiDevicePathLibConvertTextToDeviceNode (DeviceNodeStr);
  2788. NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
  2789. free (DevicePath);
  2790. free (DeviceNode);
  2791. DevicePath = NewDevicePath;
  2792. if (IsInstanceEnd) {
  2793. DeviceNode = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);
  2794. ASSERT (DeviceNode != NULL);
  2795. SetDevicePathEndNode (DeviceNode);
  2796. DeviceNode->SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE;
  2797. NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
  2798. free (DevicePath);
  2799. free (DeviceNode);
  2800. DevicePath = NewDevicePath;
  2801. }
  2802. }
  2803. free (DevicePathStr);
  2804. return DevicePath;
  2805. }