]>
Commit | Line | Data |
---|---|---|
a405b86d | 1 | /** @file\r |
2 | Main file for support of shell consist mapping.\r | |
3 | \r | |
53173337 | 4 | Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>\r |
a405b86d | 5 | This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | **/\r | |
13 | \r | |
14 | #include "UefiShellCommandLib.h"\r | |
15 | #include <Library/DevicePathLib.h>\r | |
16 | #include <Library/SortLib.h>\r | |
cc4c3312 | 17 | #include <Library/UefiLib.h>\r |
0db3fade | 18 | #include <Protocol/UsbIo.h>\r |
a405b86d | 19 | \r |
20 | typedef enum {\r | |
21 | MTDTypeUnknown,\r | |
22 | MTDTypeFloppy,\r | |
23 | MTDTypeHardDisk,\r | |
24 | MTDTypeCDRom,\r | |
25 | MTDTypeEnd\r | |
26 | } MTD_TYPE;\r | |
27 | \r | |
28 | typedef struct {\r | |
29 | CHAR16 *Str;\r | |
30 | UINTN Len;\r | |
31 | } POOL_PRINT;\r | |
32 | \r | |
33 | typedef struct {\r | |
1a63ec8f | 34 | UINTN Hi;\r |
35 | MTD_TYPE Mtd;\r | |
36 | POOL_PRINT Csd;\r | |
a405b86d | 37 | BOOLEAN Digital;\r |
38 | } DEVICE_CONSIST_MAPPING_INFO;\r | |
39 | \r | |
40 | typedef struct {\r | |
41 | MTD_TYPE MTDType;\r | |
42 | CHAR16 *Name;\r | |
43 | } MTD_NAME;\r | |
44 | \r | |
41089802 ED |
45 | /**\r |
46 | Serial Decode function.\r | |
47 | \r | |
48 | @param DevPath The Device path info.\r | |
49 | @param MapInfo The map info.\r | |
50 | @param OrigDevPath The original device path protocol.\r | |
51 | \r | |
52 | **/\r | |
53 | typedef \r | |
54 | VOID \r | |
55 | (EFIAPI *SERIAL_DECODE_FUNCTION) (\r | |
56 | EFI_DEVICE_PATH_PROTOCOL *DevPath, \r | |
57 | DEVICE_CONSIST_MAPPING_INFO *MapInfo,\r | |
58 | EFI_DEVICE_PATH_PROTOCOL *OrigDevPath\r | |
59 | );\r | |
0db3fade | 60 | \r |
a405b86d | 61 | typedef struct {\r |
62 | UINT8 Type;\r | |
63 | UINT8 SubType;\r | |
41089802 | 64 | SERIAL_DECODE_FUNCTION SerialFun;\r |
1a63ec8f | 65 | INTN (EFIAPI *CompareFun) (EFI_DEVICE_PATH_PROTOCOL *DevPath, EFI_DEVICE_PATH_PROTOCOL *DevPath2);\r |
a405b86d | 66 | } DEV_PATH_CONSIST_MAPPING_TABLE;\r |
67 | \r | |
68 | \r | |
69 | /**\r | |
70 | Concatenates a formatted unicode string to allocated pool.\r | |
71 | The caller must free the resulting buffer.\r | |
72 | \r | |
73 | @param Str Tracks the allocated pool, size in use, and amount of pool allocated.\r | |
74 | @param Fmt The format string\r | |
75 | @param ... The data will be printed.\r | |
76 | \r | |
77 | @return Allocated buffer with the formatted string printed in it.\r | |
78 | The caller must free the allocated buffer.\r | |
79 | The buffer allocation is not packed.\r | |
80 | \r | |
81 | **/\r | |
82 | CHAR16 *\r | |
83 | EFIAPI\r | |
84 | CatPrint (\r | |
85 | IN OUT POOL_PRINT *Str,\r | |
86 | IN CHAR16 *Fmt,\r | |
87 | ...\r | |
88 | )\r | |
89 | {\r | |
90 | UINT16 *AppendStr;\r | |
91 | VA_LIST Args;\r | |
92 | UINTN StringSize;\r | |
93 | \r | |
94 | AppendStr = AllocateZeroPool (0x1000);\r | |
95 | if (AppendStr == NULL) {\r | |
96 | ASSERT(FALSE);\r | |
97 | return Str->Str;\r | |
98 | }\r | |
99 | \r | |
100 | VA_START (Args, Fmt);\r | |
101 | UnicodeVSPrint (AppendStr, 0x1000, Fmt, Args);\r | |
102 | VA_END (Args);\r | |
103 | if (NULL == Str->Str) {\r | |
104 | StringSize = StrSize (AppendStr);\r | |
105 | Str->Str = AllocateZeroPool (StringSize);\r | |
106 | ASSERT (Str->Str != NULL);\r | |
107 | } else {\r | |
108 | StringSize = StrSize (AppendStr);\r | |
109 | StringSize += (StrSize (Str->Str) - sizeof (UINT16));\r | |
110 | \r | |
111 | Str->Str = ReallocatePool (\r | |
112 | StrSize (Str->Str),\r | |
113 | StringSize,\r | |
114 | Str->Str\r | |
115 | );\r | |
116 | ASSERT (Str->Str != NULL);\r | |
117 | }\r | |
118 | \r | |
53173337 | 119 | StrnCat (Str->Str, AppendStr, StringSize/sizeof(CHAR16) - 1 - StrLen(Str->Str));\r |
a405b86d | 120 | Str->Len = StringSize;\r |
121 | \r | |
122 | FreePool (AppendStr);\r | |
123 | return Str->Str;\r | |
124 | }\r | |
125 | \r | |
126 | MTD_NAME mMTDName[] = {\r | |
127 | {\r | |
128 | MTDTypeUnknown,\r | |
129 | L"F"\r | |
130 | },\r | |
131 | {\r | |
132 | MTDTypeFloppy,\r | |
133 | L"FP"\r | |
134 | },\r | |
135 | {\r | |
136 | MTDTypeHardDisk,\r | |
137 | L"HD"\r | |
138 | },\r | |
139 | {\r | |
140 | MTDTypeCDRom,\r | |
141 | L"CD"\r | |
142 | },\r | |
143 | {\r | |
144 | MTDTypeEnd,\r | |
145 | NULL\r | |
146 | }\r | |
147 | };\r | |
148 | \r | |
1a63ec8f | 149 | /**\r |
150 | Function to append a 64 bit number / 25 onto the string.\r | |
151 | \r | |
4ff7e37b ED |
152 | @param[in, out] Str The string so append onto.\r |
153 | @param[in] Num The number to divide and append.\r | |
1a63ec8f | 154 | \r |
155 | @retval EFI_INVALID_PARAMETER A parameter was NULL.\r | |
156 | @retval EFI_SUCCESS The appending was successful.\r | |
157 | **/\r | |
158 | EFI_STATUS\r | |
159 | EFIAPI\r | |
a405b86d | 160 | AppendCSDNum2 (\r |
161 | IN OUT POOL_PRINT *Str,\r | |
162 | IN UINT64 Num\r | |
163 | )\r | |
164 | {\r | |
165 | UINT64 Result;\r | |
166 | UINT32 Rem;\r | |
167 | \r | |
1a63ec8f | 168 | if (Str == NULL) {\r |
169 | return (EFI_INVALID_PARAMETER);\r | |
170 | }\r | |
a405b86d | 171 | \r |
172 | Result = DivU64x32Remainder (Num, 25, &Rem);\r | |
173 | if (Result > 0) {\r | |
174 | AppendCSDNum2 (Str, Result);\r | |
175 | }\r | |
176 | \r | |
177 | CatPrint (Str, L"%c", Rem + 'a');\r | |
1a63ec8f | 178 | return (EFI_SUCCESS);\r |
a405b86d | 179 | }\r |
180 | \r | |
1a63ec8f | 181 | /**\r |
182 | Function to append a 64 bit number onto the mapping info.\r | |
183 | \r | |
4ff7e37b ED |
184 | @param[in, out] MappingItem The mapping info object to append onto.\r |
185 | @param[in] Num The info to append.\r | |
1a63ec8f | 186 | \r |
187 | @retval EFI_INVALID_PARAMETER A parameter was NULL.\r | |
188 | @retval EFI_SUCCESS The appending was successful.\r | |
189 | **/\r | |
190 | EFI_STATUS\r | |
191 | EFIAPI\r | |
a405b86d | 192 | AppendCSDNum (\r |
1a63ec8f | 193 | IN OUT DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
194 | IN UINT64 Num\r | |
a405b86d | 195 | )\r |
196 | {\r | |
1a63ec8f | 197 | if (MappingItem == NULL) {\r |
198 | return EFI_INVALID_PARAMETER;\r | |
199 | }\r | |
a405b86d | 200 | \r |
201 | if (MappingItem->Digital) {\r | |
1a63ec8f | 202 | CatPrint (&MappingItem->Csd, L"%ld", Num);\r |
a405b86d | 203 | } else {\r |
1a63ec8f | 204 | AppendCSDNum2 (&MappingItem->Csd, Num);\r |
a405b86d | 205 | }\r |
206 | \r | |
207 | MappingItem->Digital = (BOOLEAN)!(MappingItem->Digital);\r | |
1a63ec8f | 208 | \r |
209 | return (EFI_SUCCESS);\r | |
a405b86d | 210 | }\r |
211 | \r | |
1a63ec8f | 212 | /**\r |
213 | Function to append string into the mapping info.\r | |
214 | \r | |
4ff7e37b ED |
215 | @param[in, out] MappingItem The mapping info object to append onto.\r |
216 | @param[in] Str The info to append.\r | |
1a63ec8f | 217 | \r |
218 | @retval EFI_INVALID_PARAMETER A parameter was NULL.\r | |
219 | @retval EFI_SUCCESS The appending was successful.\r | |
220 | **/\r | |
221 | EFI_STATUS\r | |
222 | EFIAPI\r | |
a405b86d | 223 | AppendCSDStr (\r |
1a63ec8f | 224 | IN OUT DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
225 | IN CHAR16 *Str\r | |
a405b86d | 226 | )\r |
227 | {\r | |
228 | CHAR16 *Index;\r | |
229 | \r | |
1a63ec8f | 230 | if (Str == NULL || MappingItem == NULL) {\r |
231 | return (EFI_INVALID_PARAMETER);\r | |
232 | }\r | |
a405b86d | 233 | \r |
234 | if (MappingItem->Digital) {\r | |
235 | //\r | |
236 | // To aVOID mult-meaning, the mapping is:\r | |
237 | // 0 1 2 3 4 5 6 7 8 9 a b c d e f\r | |
238 | // 0 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15\r | |
239 | //\r | |
240 | for (Index = Str; *Index != 0; Index++) {\r | |
241 | switch (*Index) {\r | |
242 | case '0':\r | |
243 | case '2':\r | |
244 | case '3':\r | |
245 | case '4':\r | |
246 | case '5':\r | |
247 | case '6':\r | |
248 | case '7':\r | |
249 | case '8':\r | |
250 | case '9':\r | |
1a63ec8f | 251 | CatPrint (&MappingItem->Csd, L"%c", *Index);\r |
a405b86d | 252 | break;\r |
253 | \r | |
254 | case '1':\r | |
1a63ec8f | 255 | CatPrint (&MappingItem->Csd, L"16");\r |
a405b86d | 256 | break;\r |
257 | \r | |
258 | case 'a':\r | |
259 | case 'b':\r | |
260 | case 'c':\r | |
261 | case 'd':\r | |
262 | case 'e':\r | |
263 | case 'f':\r | |
1a63ec8f | 264 | CatPrint (&MappingItem->Csd, L"1%c", *Index - 'a' + '0');\r |
a405b86d | 265 | break;\r |
266 | \r | |
267 | case 'A':\r | |
268 | case 'B':\r | |
269 | case 'C':\r | |
270 | case 'D':\r | |
271 | case 'E':\r | |
272 | case 'F':\r | |
1a63ec8f | 273 | CatPrint (&MappingItem->Csd, L"1%c", *Index - 'A' + '0');\r |
a405b86d | 274 | break;\r |
275 | }\r | |
276 | }\r | |
277 | } else {\r | |
278 | for (Index = Str; *Index != 0; Index++) {\r | |
279 | //\r | |
280 | // The mapping is:\r | |
281 | // 0 1 2 3 4 5 6 7 8 9 a b c d e f\r | |
282 | // a b c d e f g h i j k l m n o p\r | |
283 | //\r | |
284 | if (*Index >= '0' && *Index <= '9') {\r | |
1a63ec8f | 285 | CatPrint (&MappingItem->Csd, L"%c", *Index - '0' + 'a');\r |
a405b86d | 286 | } else if (*Index >= 'a' && *Index <= 'f') {\r |
1a63ec8f | 287 | CatPrint (&MappingItem->Csd, L"%c", *Index - 'a' + 'k');\r |
a405b86d | 288 | } else if (*Index >= 'A' && *Index <= 'F') {\r |
1a63ec8f | 289 | CatPrint (&MappingItem->Csd, L"%c", *Index - 'A' + 'k');\r |
a405b86d | 290 | }\r |
291 | }\r | |
292 | }\r | |
293 | \r | |
294 | MappingItem->Digital = (BOOLEAN)!(MappingItem->Digital);\r | |
1a63ec8f | 295 | \r |
296 | return (EFI_SUCCESS);\r | |
a405b86d | 297 | }\r |
298 | \r | |
1a63ec8f | 299 | /**\r |
300 | Function to append a Guid to the mapping item.\r | |
301 | \r | |
4ff7e37b ED |
302 | @param[in, out] MappingItem The item to append onto.\r |
303 | @param[in] Guid The guid to append.\r | |
1a63ec8f | 304 | \r |
305 | @retval EFI_SUCCESS The appending operation was successful.\r | |
306 | @retval EFI_INVALID_PARAMETER A parameter was NULL.\r | |
307 | **/\r | |
308 | EFI_STATUS\r | |
309 | EFIAPI\r | |
a405b86d | 310 | AppendCSDGuid (\r |
311 | DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r | |
312 | EFI_GUID *Guid\r | |
313 | )\r | |
314 | {\r | |
315 | CHAR16 Buffer[64];\r | |
1a63ec8f | 316 | \r |
317 | if (Guid == NULL || MappingItem == NULL) {\r | |
318 | return (EFI_INVALID_PARAMETER);\r | |
319 | }\r | |
a405b86d | 320 | \r |
321 | UnicodeSPrint (\r | |
322 | Buffer,\r | |
323 | 0,\r | |
324 | L"%g",\r | |
325 | Guid\r | |
326 | );\r | |
1a63ec8f | 327 | \r |
a405b86d | 328 | AppendCSDStr (MappingItem, Buffer);\r |
1a63ec8f | 329 | \r |
330 | return (EFI_SUCCESS);\r | |
a405b86d | 331 | }\r |
332 | \r | |
1a63ec8f | 333 | /**\r |
334 | Function to compare 2 APCI device paths.\r | |
335 | \r | |
336 | @param[in] DevicePath1 The first device path to compare.\r | |
337 | @param[in] DevicePath2 The second device path to compare.\r | |
338 | \r | |
339 | @retval 0 The device paths represent the same device.\r | |
340 | @return Non zero if the devices are different, zero otherwise.\r | |
341 | **/\r | |
a405b86d | 342 | INTN\r |
e26d7b59 | 343 | EFIAPI\r |
1a63ec8f | 344 | DevPathCompareAcpi (\r |
a405b86d | 345 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath1,\r |
346 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath2\r | |
347 | )\r | |
348 | {\r | |
349 | ACPI_HID_DEVICE_PATH *Acpi1;\r | |
350 | ACPI_HID_DEVICE_PATH *Acpi2;\r | |
351 | \r | |
1a63ec8f | 352 | if (DevicePath1 == NULL || DevicePath2 == NULL) {\r |
353 | return (-2);\r | |
354 | }\r | |
a405b86d | 355 | \r |
356 | Acpi1 = (ACPI_HID_DEVICE_PATH *) DevicePath1;\r | |
357 | Acpi2 = (ACPI_HID_DEVICE_PATH *) DevicePath2;\r | |
358 | if (Acpi1->HID > Acpi2->HID || (Acpi1->HID == Acpi2->HID && Acpi1->UID > Acpi2->UID)) {\r | |
359 | return 1;\r | |
360 | }\r | |
361 | \r | |
362 | if (Acpi1->HID == Acpi2->HID && Acpi1->UID == Acpi2->UID) {\r | |
363 | return 0;\r | |
364 | }\r | |
365 | \r | |
366 | return -1;\r | |
367 | }\r | |
368 | \r | |
1a63ec8f | 369 | /**\r |
370 | Function to compare 2 PCI device paths.\r | |
371 | \r | |
372 | @param[in] DevicePath1 The first device path to compare.\r | |
373 | @param[in] DevicePath2 The second device path to compare.\r | |
374 | \r | |
375 | @retval 0 The device paths represent the same device.\r | |
376 | @return Non zero if the devices are different, zero otherwise.\r | |
377 | **/\r | |
a405b86d | 378 | INTN\r |
e26d7b59 | 379 | EFIAPI\r |
1a63ec8f | 380 | DevPathComparePci (\r |
a405b86d | 381 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath1,\r |
382 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath2\r | |
383 | )\r | |
384 | {\r | |
385 | PCI_DEVICE_PATH *Pci1;\r | |
386 | PCI_DEVICE_PATH *Pci2;\r | |
387 | \r | |
388 | ASSERT(DevicePath1 != NULL);\r | |
389 | ASSERT(DevicePath2 != NULL);\r | |
390 | \r | |
391 | Pci1 = (PCI_DEVICE_PATH *) DevicePath1;\r | |
392 | Pci2 = (PCI_DEVICE_PATH *) DevicePath2;\r | |
393 | if (Pci1->Device > Pci2->Device || (Pci1->Device == Pci2->Device && Pci1->Function > Pci2->Function)) {\r | |
394 | return 1;\r | |
395 | }\r | |
396 | \r | |
397 | if (Pci1->Device == Pci2->Device && Pci1->Function == Pci2->Function) {\r | |
398 | return 0;\r | |
399 | }\r | |
400 | \r | |
401 | return -1;\r | |
402 | }\r | |
403 | \r | |
404 | /**\r | |
405 | Do a comparison on 2 device paths.\r | |
406 | \r | |
407 | @param[in] DevicePath1 The first device path.\r | |
408 | @param[in] DevicePath2 The second device path.\r | |
409 | \r | |
410 | @retval 0 The 2 device paths are the same.\r | |
411 | @retval <0 DevicePath2 is greater than DevicePath1.\r | |
412 | @retval >0 DevicePath1 is greater than DevicePath2.\r | |
413 | **/\r | |
414 | INTN\r | |
415 | EFIAPI\r | |
416 | DevPathCompareDefault (\r | |
417 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath1,\r | |
418 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath2\r | |
419 | )\r | |
420 | {\r | |
421 | UINTN DevPathSize1;\r | |
422 | UINTN DevPathSize2;\r | |
423 | \r | |
424 | ASSERT(DevicePath1 != NULL);\r | |
425 | ASSERT(DevicePath2 != NULL);\r | |
426 | \r | |
427 | DevPathSize1 = DevicePathNodeLength (DevicePath1);\r | |
428 | DevPathSize2 = DevicePathNodeLength (DevicePath2);\r | |
429 | if (DevPathSize1 > DevPathSize2) {\r | |
430 | return 1;\r | |
431 | } else if (DevPathSize1 < DevPathSize2) {\r | |
432 | return -1;\r | |
433 | } else {\r | |
434 | return CompareMem (DevicePath1, DevicePath2, DevPathSize1);\r | |
435 | }\r | |
436 | }\r | |
437 | \r | |
438 | /**\r | |
439 | DevicePathNode must be SerialHDD Channel type and this will populate the MappingItem.\r | |
440 | \r | |
441 | @param[in] DevicePathNode The node to get info on.\r | |
442 | @param[in] MappingItem The info item to populate.\r | |
41089802 | 443 | @param[in] DevicePath Ignored.\r |
a405b86d | 444 | **/\r |
445 | VOID\r | |
446 | EFIAPI\r | |
447 | DevPathSerialHardDrive (\r | |
448 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
0db3fade | 449 | IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
450 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
a405b86d | 451 | )\r |
452 | {\r | |
453 | HARDDRIVE_DEVICE_PATH *Hd;\r | |
454 | \r | |
455 | ASSERT(DevicePathNode != NULL);\r | |
456 | ASSERT(MappingItem != NULL);\r | |
457 | \r | |
458 | Hd = (HARDDRIVE_DEVICE_PATH *) DevicePathNode;\r | |
1a63ec8f | 459 | if (MappingItem->Mtd == MTDTypeUnknown) {\r |
460 | MappingItem->Mtd = MTDTypeHardDisk;\r | |
a405b86d | 461 | }\r |
462 | \r | |
463 | AppendCSDNum (MappingItem, Hd->PartitionNumber);\r | |
464 | }\r | |
465 | \r | |
466 | /**\r | |
467 | DevicePathNode must be SerialAtapi Channel type and this will populate the MappingItem.\r | |
468 | \r | |
469 | @param[in] DevicePathNode The node to get info on.\r | |
470 | @param[in] MappingItem The info item to populate.\r | |
41089802 | 471 | @param[in] DevicePath Ignored.\r |
a405b86d | 472 | **/\r |
473 | VOID\r | |
474 | EFIAPI\r | |
475 | DevPathSerialAtapi (\r | |
476 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
0db3fade | 477 | IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
478 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
a405b86d | 479 | )\r |
480 | {\r | |
481 | ATAPI_DEVICE_PATH *Atapi;\r | |
482 | \r | |
483 | ASSERT(DevicePathNode != NULL);\r | |
484 | ASSERT(MappingItem != NULL);\r | |
485 | \r | |
486 | Atapi = (ATAPI_DEVICE_PATH *) DevicePathNode;\r | |
487 | AppendCSDNum (MappingItem, (Atapi->PrimarySecondary * 2 + Atapi->SlaveMaster));\r | |
488 | }\r | |
489 | \r | |
490 | /**\r | |
491 | DevicePathNode must be SerialCDROM Channel type and this will populate the MappingItem.\r | |
492 | \r | |
493 | @param[in] DevicePathNode The node to get info on.\r | |
494 | @param[in] MappingItem The info item to populate.\r | |
41089802 | 495 | @param[in] DevicePath Ignored.\r |
a405b86d | 496 | **/\r |
497 | VOID\r | |
498 | EFIAPI\r | |
499 | DevPathSerialCdRom (\r | |
500 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
0db3fade | 501 | IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
502 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
a405b86d | 503 | )\r |
504 | {\r | |
505 | CDROM_DEVICE_PATH *Cd;\r | |
506 | \r | |
507 | ASSERT(DevicePathNode != NULL);\r | |
508 | ASSERT(MappingItem != NULL);\r | |
509 | \r | |
510 | Cd = (CDROM_DEVICE_PATH *) DevicePathNode;\r | |
1a63ec8f | 511 | MappingItem->Mtd = MTDTypeCDRom;\r |
a405b86d | 512 | AppendCSDNum (MappingItem, Cd->BootEntry);\r |
513 | }\r | |
514 | \r | |
515 | /**\r | |
516 | DevicePathNode must be SerialFibre Channel type and this will populate the MappingItem.\r | |
517 | \r | |
518 | @param[in] DevicePathNode The node to get info on.\r | |
519 | @param[in] MappingItem The info item to populate.\r | |
41089802 | 520 | @param[in] DevicePath Ignored.\r |
a405b86d | 521 | **/\r |
522 | VOID\r | |
523 | EFIAPI\r | |
524 | DevPathSerialFibre (\r | |
525 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
0db3fade | 526 | IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
527 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
a405b86d | 528 | )\r |
529 | {\r | |
530 | FIBRECHANNEL_DEVICE_PATH *Fibre;\r | |
531 | \r | |
532 | ASSERT(DevicePathNode != NULL);\r | |
533 | ASSERT(MappingItem != NULL);\r | |
534 | \r | |
535 | Fibre = (FIBRECHANNEL_DEVICE_PATH *) DevicePathNode;\r | |
536 | AppendCSDNum (MappingItem, Fibre->WWN);\r | |
537 | AppendCSDNum (MappingItem, Fibre->Lun);\r | |
538 | }\r | |
539 | \r | |
540 | /**\r | |
541 | DevicePathNode must be SerialUart type and this will populate the MappingItem.\r | |
542 | \r | |
543 | @param[in] DevicePathNode The node to get info on.\r | |
544 | @param[in] MappingItem The info item to populate.\r | |
41089802 | 545 | @param[in] DevicePath Ignored.\r |
a405b86d | 546 | **/\r |
547 | VOID\r | |
548 | EFIAPI\r | |
549 | DevPathSerialUart (\r | |
550 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
0db3fade | 551 | IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
552 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
a405b86d | 553 | )\r |
554 | {\r | |
555 | UART_DEVICE_PATH *Uart;\r | |
556 | \r | |
557 | ASSERT(DevicePathNode != NULL);\r | |
558 | ASSERT(MappingItem != NULL);\r | |
559 | \r | |
560 | Uart = (UART_DEVICE_PATH *) DevicePathNode;\r | |
561 | AppendCSDNum (MappingItem, Uart->BaudRate);\r | |
562 | AppendCSDNum (MappingItem, Uart->DataBits);\r | |
563 | AppendCSDNum (MappingItem, Uart->Parity);\r | |
564 | AppendCSDNum (MappingItem, Uart->StopBits);\r | |
565 | }\r | |
566 | \r | |
567 | /**\r | |
568 | DevicePathNode must be SerialUSB type and this will populate the MappingItem.\r | |
569 | \r | |
570 | @param[in] DevicePathNode The node to get info on.\r | |
571 | @param[in] MappingItem The info item to populate.\r | |
41089802 | 572 | @param[in] DevicePath Ignored.\r |
a405b86d | 573 | **/\r |
574 | VOID\r | |
575 | EFIAPI\r | |
576 | DevPathSerialUsb (\r | |
577 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
0db3fade | 578 | IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
579 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
a405b86d | 580 | )\r |
581 | {\r | |
0db3fade | 582 | USB_DEVICE_PATH *Usb;\r |
583 | EFI_USB_IO_PROTOCOL *UsbIo;\r | |
584 | EFI_HANDLE TempHandle;\r | |
585 | EFI_STATUS Status;\r | |
586 | USB_INTERFACE_DESCRIPTOR InterfaceDesc;\r | |
587 | \r | |
a405b86d | 588 | \r |
589 | ASSERT(DevicePathNode != NULL);\r | |
590 | ASSERT(MappingItem != NULL);\r | |
591 | \r | |
592 | Usb = (USB_DEVICE_PATH *) DevicePathNode;\r | |
593 | AppendCSDNum (MappingItem, Usb->ParentPortNumber);\r | |
594 | AppendCSDNum (MappingItem, Usb->InterfaceNumber);\r | |
0db3fade | 595 | \r |
596 | if (PcdGetBool(PcdUsbExtendedDecode)) {\r | |
597 | Status = gBS->LocateDevicePath( &gEfiUsbIoProtocolGuid, &DevicePath, &TempHandle );\r | |
598 | UsbIo = NULL;\r | |
599 | if (!EFI_ERROR(Status)) {\r | |
600 | Status = gBS->OpenProtocol(TempHandle, &gEfiUsbIoProtocolGuid, (VOID**)&UsbIo, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r | |
601 | } \r | |
602 | \r | |
603 | if (!EFI_ERROR(Status)) {\r | |
604 | ASSERT(UsbIo != NULL);\r | |
605 | Status = UsbIo->UsbGetInterfaceDescriptor(UsbIo, &InterfaceDesc);\r | |
606 | if (!EFI_ERROR(Status)) {\r | |
607 | if (InterfaceDesc.InterfaceClass == USB_MASS_STORE_CLASS && MappingItem->Mtd == MTDTypeUnknown) {\r | |
608 | switch (InterfaceDesc.InterfaceSubClass){\r | |
609 | case USB_MASS_STORE_SCSI:\r | |
610 | MappingItem->Mtd = MTDTypeHardDisk;\r | |
611 | break;\r | |
612 | case USB_MASS_STORE_8070I:\r | |
613 | case USB_MASS_STORE_UFI:\r | |
614 | MappingItem->Mtd = MTDTypeFloppy;\r | |
615 | break;\r | |
616 | case USB_MASS_STORE_8020I:\r | |
617 | MappingItem->Mtd = MTDTypeCDRom;\r | |
618 | break;\r | |
619 | }\r | |
620 | }\r | |
621 | }\r | |
622 | } \r | |
623 | }\r | |
a405b86d | 624 | }\r |
625 | \r | |
626 | /**\r | |
627 | DevicePathNode must be SerialVendor type and this will populate the MappingItem.\r | |
628 | \r | |
629 | @param[in] DevicePathNode The node to get info on.\r | |
630 | @param[in] MappingItem The info item to populate.\r | |
41089802 | 631 | @param[in] DevicePath Ignored.\r |
1a63ec8f | 632 | \r |
a405b86d | 633 | **/\r |
634 | VOID\r | |
635 | EFIAPI\r | |
636 | DevPathSerialVendor (\r | |
637 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
0db3fade | 638 | IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
639 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
a405b86d | 640 | )\r |
641 | {\r | |
642 | VENDOR_DEVICE_PATH *Vendor;\r | |
643 | SAS_DEVICE_PATH *Sas;\r | |
cc4c3312 | 644 | UINTN TargetNameLength;\r |
645 | UINTN Index;\r | |
646 | CHAR16 *Buffer;\r | |
a405b86d | 647 | \r |
1a63ec8f | 648 | if (DevicePathNode == NULL || MappingItem == NULL) {\r |
649 | return;\r | |
650 | }\r | |
a405b86d | 651 | \r |
652 | Vendor = (VENDOR_DEVICE_PATH *) DevicePathNode;\r | |
653 | AppendCSDGuid (MappingItem, &Vendor->Guid);\r | |
654 | \r | |
1a63ec8f | 655 | if (CompareGuid (&gEfiSasDevicePathGuid, &Vendor->Guid)) {\r |
a405b86d | 656 | Sas = (SAS_DEVICE_PATH *) Vendor;\r |
657 | AppendCSDNum (MappingItem, Sas->SasAddress);\r | |
658 | AppendCSDNum (MappingItem, Sas->Lun);\r | |
659 | AppendCSDNum (MappingItem, Sas->DeviceTopology);\r | |
660 | AppendCSDNum (MappingItem, Sas->RelativeTargetPort);\r | |
cc4c3312 | 661 | } else {\r |
662 | TargetNameLength = MIN(DevicePathNodeLength (DevicePathNode) - sizeof (VENDOR_DEVICE_PATH), PcdGet32(PcdShellVendorExtendedDecode));\r | |
663 | if (TargetNameLength != 0) {\r | |
664 | //\r | |
665 | // String is 2 chars per data byte, plus NULL terminator\r | |
666 | //\r | |
667 | Buffer = AllocateZeroPool (((TargetNameLength * 2) + 1) * sizeof(CHAR16));\r | |
668 | ASSERT(Buffer != NULL);\r | |
669 | if (Buffer == NULL) {\r | |
670 | return;\r | |
0db3fade | 671 | }\r |
cc4c3312 | 672 | \r |
673 | //\r | |
674 | // Build the string data\r | |
675 | //\r | |
676 | for (Index = 0; Index < TargetNameLength; Index++) {\r | |
677 | Buffer = CatSPrint (Buffer, L"%02x", *((UINT8*)Vendor + sizeof (VENDOR_DEVICE_PATH) + Index));\r | |
0db3fade | 678 | }\r |
cc4c3312 | 679 | \r |
680 | //\r | |
681 | // Append the new data block\r | |
682 | //\r | |
683 | AppendCSDStr (MappingItem, Buffer);\r | |
684 | \r | |
685 | FreePool(Buffer);\r | |
686 | }\r | |
a405b86d | 687 | }\r |
688 | }\r | |
689 | \r | |
690 | /**\r | |
691 | DevicePathNode must be SerialLun type and this will populate the MappingItem.\r | |
692 | \r | |
693 | @param[in] DevicePathNode The node to get info on.\r | |
694 | @param[in] MappingItem The info item to populate.\r | |
41089802 | 695 | @param[in] DevicePath Ignored.\r |
a405b86d | 696 | **/\r |
697 | VOID\r | |
698 | EFIAPI\r | |
699 | DevPathSerialLun (\r | |
700 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
0db3fade | 701 | IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
702 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
a405b86d | 703 | )\r |
704 | {\r | |
705 | DEVICE_LOGICAL_UNIT_DEVICE_PATH *Lun;\r | |
706 | \r | |
707 | ASSERT(DevicePathNode != NULL);\r | |
708 | ASSERT(MappingItem != NULL);\r | |
709 | \r | |
710 | Lun = (DEVICE_LOGICAL_UNIT_DEVICE_PATH *) DevicePathNode;\r | |
711 | AppendCSDNum (MappingItem, Lun->Lun);\r | |
712 | }\r | |
713 | \r | |
714 | /**\r | |
715 | DevicePathNode must be SerialSata type and this will populate the MappingItem.\r | |
716 | \r | |
717 | @param[in] DevicePathNode The node to get info on.\r | |
718 | @param[in] MappingItem The info item to populate.\r | |
41089802 | 719 | @param[in] DevicePath Ignored.\r |
a405b86d | 720 | **/\r |
721 | VOID\r | |
722 | EFIAPI\r | |
723 | DevPathSerialSata (\r | |
724 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
0db3fade | 725 | IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
726 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
a405b86d | 727 | )\r |
728 | {\r | |
729 | SATA_DEVICE_PATH *Sata;\r | |
730 | \r | |
731 | ASSERT(DevicePathNode != NULL);\r | |
732 | ASSERT(MappingItem != NULL);\r | |
733 | \r | |
734 | Sata = (SATA_DEVICE_PATH *) DevicePathNode;\r | |
735 | AppendCSDNum (MappingItem, Sata->HBAPortNumber);\r | |
736 | AppendCSDNum (MappingItem, Sata->PortMultiplierPortNumber);\r | |
737 | AppendCSDNum (MappingItem, Sata->Lun);\r | |
738 | }\r | |
739 | \r | |
740 | /**\r | |
741 | DevicePathNode must be SerialSCSI type and this will populate the MappingItem.\r | |
742 | \r | |
743 | @param[in] DevicePathNode The node to get info on.\r | |
744 | @param[in] MappingItem The info item to populate.\r | |
41089802 | 745 | @param[in] DevicePath Ignored.\r |
a405b86d | 746 | **/\r |
747 | VOID\r | |
748 | EFIAPI\r | |
749 | DevPathSerialIScsi (\r | |
750 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
0db3fade | 751 | IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
752 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
a405b86d | 753 | )\r |
754 | {\r | |
a405b86d | 755 | ISCSI_DEVICE_PATH *IScsi;\r |
756 | UINT8 *IScsiTargetName;\r | |
757 | CHAR16 *TargetName;\r | |
758 | UINTN TargetNameLength;\r | |
759 | UINTN Index;\r | |
760 | \r | |
761 | ASSERT(DevicePathNode != NULL);\r | |
762 | ASSERT(MappingItem != NULL);\r | |
763 | \r | |
9b589522 JC |
764 | if (PcdGetBool(PcdShellDecodeIScsiMapNames)) {\r |
765 | IScsi = (ISCSI_DEVICE_PATH *) DevicePathNode;\r | |
766 | AppendCSDNum (MappingItem, IScsi->NetworkProtocol);\r | |
767 | AppendCSDNum (MappingItem, IScsi->LoginOption);\r | |
768 | AppendCSDNum (MappingItem, IScsi->Lun);\r | |
769 | AppendCSDNum (MappingItem, IScsi->TargetPortalGroupTag);\r | |
770 | TargetNameLength = DevicePathNodeLength (DevicePathNode) - sizeof (ISCSI_DEVICE_PATH);\r | |
771 | if (TargetNameLength > 0) {\r | |
772 | TargetName = AllocateZeroPool ((TargetNameLength + 1) * sizeof (CHAR16));\r | |
773 | if (TargetName != NULL) {\r | |
774 | IScsiTargetName = (UINT8 *) (IScsi + 1);\r | |
775 | for (Index = 0; Index < TargetNameLength; Index++) {\r | |
776 | TargetName[Index] = (CHAR16) IScsiTargetName[Index];\r | |
777 | }\r | |
778 | AppendCSDStr (MappingItem, TargetName);\r | |
779 | FreePool (TargetName);\r | |
a405b86d | 780 | }\r |
a405b86d | 781 | }\r |
782 | }\r | |
a405b86d | 783 | }\r |
784 | \r | |
785 | /**\r | |
786 | DevicePathNode must be SerialI20 type and this will populate the MappingItem.\r | |
787 | \r | |
788 | @param[in] DevicePathNode The node to get info on.\r | |
789 | @param[in] MappingItem The info item to populate.\r | |
41089802 | 790 | @param[in] DevicePath Ignored.\r |
a405b86d | 791 | **/\r |
792 | VOID\r | |
793 | EFIAPI\r | |
794 | DevPathSerialI2O (\r | |
795 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
0db3fade | 796 | IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
797 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
a405b86d | 798 | )\r |
799 | {\r | |
1a63ec8f | 800 | I2O_DEVICE_PATH *DevicePath_I20;\r |
a405b86d | 801 | \r |
802 | ASSERT(DevicePathNode != NULL);\r | |
803 | ASSERT(MappingItem != NULL);\r | |
804 | \r | |
1a63ec8f | 805 | DevicePath_I20 = (I2O_DEVICE_PATH *) DevicePathNode;\r |
806 | AppendCSDNum (MappingItem, DevicePath_I20->Tid);\r | |
a405b86d | 807 | }\r |
808 | \r | |
809 | /**\r | |
810 | DevicePathNode must be Mac Address type and this will populate the MappingItem.\r | |
811 | \r | |
812 | @param[in] DevicePathNode The node to get info on.\r | |
813 | @param[in] MappingItem The info item to populate.\r | |
41089802 | 814 | @param[in] DevicePath Ignored.\r |
a405b86d | 815 | **/\r |
816 | VOID\r | |
817 | EFIAPI\r | |
818 | DevPathSerialMacAddr (\r | |
819 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
0db3fade | 820 | IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
821 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
a405b86d | 822 | )\r |
823 | {\r | |
824 | MAC_ADDR_DEVICE_PATH *Mac;\r | |
825 | UINTN HwAddressSize;\r | |
826 | UINTN Index;\r | |
827 | CHAR16 Buffer[64];\r | |
828 | CHAR16 *PBuffer;\r | |
829 | \r | |
830 | ASSERT(DevicePathNode != NULL);\r | |
831 | ASSERT(MappingItem != NULL);\r | |
832 | \r | |
833 | Mac = (MAC_ADDR_DEVICE_PATH *) DevicePathNode;\r | |
834 | \r | |
835 | HwAddressSize = sizeof (EFI_MAC_ADDRESS);\r | |
836 | if (Mac->IfType == 0x01 || Mac->IfType == 0x00) {\r | |
837 | HwAddressSize = 6;\r | |
838 | }\r | |
839 | \r | |
840 | for (Index = 0, PBuffer = Buffer; Index < HwAddressSize; Index++, PBuffer += 2) {\r | |
841 | UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN) Mac->MacAddress.Addr[Index]);\r | |
842 | }\r | |
843 | \r | |
844 | AppendCSDStr (MappingItem, Buffer);\r | |
845 | }\r | |
846 | \r | |
847 | /**\r | |
848 | DevicePathNode must be InfiniBand type and this will populate the MappingItem.\r | |
849 | \r | |
850 | @param[in] DevicePathNode The node to get info on.\r | |
851 | @param[in] MappingItem The info item to populate.\r | |
41089802 | 852 | @param[in] DevicePath Ignored.\r |
a405b86d | 853 | **/\r |
854 | VOID\r | |
855 | EFIAPI\r | |
856 | DevPathSerialInfiniBand (\r | |
857 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
0db3fade | 858 | IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
859 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
a405b86d | 860 | )\r |
861 | {\r | |
862 | INFINIBAND_DEVICE_PATH *InfiniBand;\r | |
863 | UINTN Index;\r | |
864 | CHAR16 Buffer[64];\r | |
865 | CHAR16 *PBuffer;\r | |
866 | \r | |
867 | ASSERT(DevicePathNode != NULL);\r | |
868 | ASSERT(MappingItem != NULL);\r | |
869 | \r | |
870 | InfiniBand = (INFINIBAND_DEVICE_PATH *) DevicePathNode;\r | |
871 | for (Index = 0, PBuffer = Buffer; Index < 16; Index++, PBuffer += 2) {\r | |
872 | UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN) InfiniBand->PortGid[Index]);\r | |
873 | }\r | |
874 | \r | |
875 | AppendCSDStr (MappingItem, Buffer);\r | |
876 | AppendCSDNum (MappingItem, InfiniBand->ServiceId);\r | |
877 | AppendCSDNum (MappingItem, InfiniBand->TargetPortId);\r | |
878 | AppendCSDNum (MappingItem, InfiniBand->DeviceId);\r | |
879 | }\r | |
880 | \r | |
881 | /**\r | |
882 | DevicePathNode must be IPv4 type and this will populate the MappingItem.\r | |
883 | \r | |
884 | @param[in] DevicePathNode The node to get info on.\r | |
885 | @param[in] MappingItem The info item to populate.\r | |
41089802 | 886 | @param[in] DevicePath Ignored.\r |
a405b86d | 887 | **/\r |
888 | VOID\r | |
889 | EFIAPI\r | |
890 | DevPathSerialIPv4 (\r | |
891 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
0db3fade | 892 | IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
893 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
a405b86d | 894 | )\r |
895 | {\r | |
896 | IPv4_DEVICE_PATH *Ip;\r | |
897 | CHAR16 Buffer[10];\r | |
898 | \r | |
899 | ASSERT(DevicePathNode != NULL);\r | |
900 | ASSERT(MappingItem != NULL);\r | |
901 | \r | |
902 | Ip = (IPv4_DEVICE_PATH *) DevicePathNode;\r | |
903 | UnicodeSPrint (\r | |
904 | Buffer,\r | |
905 | 0,\r | |
906 | L"%02x%02x%02x%02x",\r | |
907 | (UINTN) Ip->LocalIpAddress.Addr[0],\r | |
908 | (UINTN) Ip->LocalIpAddress.Addr[1],\r | |
909 | (UINTN) Ip->LocalIpAddress.Addr[2],\r | |
910 | (UINTN) Ip->LocalIpAddress.Addr[3]\r | |
911 | );\r | |
912 | AppendCSDStr (MappingItem, Buffer);\r | |
913 | AppendCSDNum (MappingItem, Ip->LocalPort);\r | |
914 | UnicodeSPrint (\r | |
915 | Buffer,\r | |
916 | 0,\r | |
917 | L"%02x%02x%02x%02x",\r | |
918 | (UINTN) Ip->RemoteIpAddress.Addr[0],\r | |
919 | (UINTN) Ip->RemoteIpAddress.Addr[1],\r | |
920 | (UINTN) Ip->RemoteIpAddress.Addr[2],\r | |
921 | (UINTN) Ip->RemoteIpAddress.Addr[3]\r | |
922 | );\r | |
923 | AppendCSDStr (MappingItem, Buffer);\r | |
924 | AppendCSDNum (MappingItem, Ip->RemotePort);\r | |
925 | }\r | |
926 | \r | |
927 | /**\r | |
928 | DevicePathNode must be IPv6 type and this will populate the MappingItem.\r | |
929 | \r | |
930 | @param[in] DevicePathNode The node to get info on.\r | |
931 | @param[in] MappingItem The info item to populate.\r | |
41089802 ED |
932 | @param[in] DevicePath Ignored.\r |
933 | \r | |
a405b86d | 934 | **/\r |
935 | VOID\r | |
936 | EFIAPI\r | |
937 | DevPathSerialIPv6 (\r | |
938 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
0db3fade | 939 | IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
940 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
a405b86d | 941 | )\r |
942 | {\r | |
943 | IPv6_DEVICE_PATH *Ip;\r | |
944 | UINTN Index;\r | |
945 | CHAR16 Buffer[64];\r | |
946 | CHAR16 *PBuffer;\r | |
947 | \r | |
948 | ASSERT(DevicePathNode != NULL);\r | |
949 | ASSERT(MappingItem != NULL);\r | |
950 | \r | |
951 | Ip = (IPv6_DEVICE_PATH *) DevicePathNode;\r | |
952 | for (Index = 0, PBuffer = Buffer; Index < 16; Index++, PBuffer += 2) {\r | |
953 | UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN) Ip->LocalIpAddress.Addr[Index]);\r | |
954 | }\r | |
955 | \r | |
956 | AppendCSDStr (MappingItem, Buffer);\r | |
957 | AppendCSDNum (MappingItem, Ip->LocalPort);\r | |
958 | for (Index = 0, PBuffer = Buffer; Index < 16; Index++, PBuffer += 2) {\r | |
959 | UnicodeSPrint (PBuffer, 0, L"%02x", (UINTN) Ip->RemoteIpAddress.Addr[Index]);\r | |
960 | }\r | |
961 | \r | |
962 | AppendCSDStr (MappingItem, Buffer);\r | |
963 | AppendCSDNum (MappingItem, Ip->RemotePort);\r | |
964 | }\r | |
965 | \r | |
966 | /**\r | |
967 | DevicePathNode must be SCSI type and this will populate the MappingItem.\r | |
968 | \r | |
969 | @param[in] DevicePathNode The node to get info on.\r | |
970 | @param[in] MappingItem The info item to populate.\r | |
41089802 ED |
971 | @param[in] DevicePath Ignored.\r |
972 | \r | |
a405b86d | 973 | **/\r |
974 | VOID\r | |
975 | EFIAPI\r | |
976 | DevPathSerialScsi (\r | |
977 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
0db3fade | 978 | IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
979 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
a405b86d | 980 | )\r |
981 | {\r | |
982 | SCSI_DEVICE_PATH *Scsi;\r | |
983 | \r | |
984 | ASSERT(DevicePathNode != NULL);\r | |
985 | ASSERT(MappingItem != NULL);\r | |
986 | \r | |
987 | Scsi = (SCSI_DEVICE_PATH *) DevicePathNode;\r | |
988 | AppendCSDNum (MappingItem, Scsi->Pun);\r | |
989 | AppendCSDNum (MappingItem, Scsi->Lun);\r | |
990 | }\r | |
991 | \r | |
992 | /**\r | |
993 | DevicePathNode must be 1394 type and this will populate the MappingItem.\r | |
994 | \r | |
995 | @param[in] DevicePathNode The node to get info on.\r | |
996 | @param[in] MappingItem The info item to populate.\r | |
41089802 | 997 | @param[in] DevicePath Ignored.\r |
a405b86d | 998 | **/\r |
999 | VOID\r | |
1000 | EFIAPI\r | |
1001 | DevPathSerial1394 (\r | |
1002 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
0db3fade | 1003 | IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
1004 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
a405b86d | 1005 | )\r |
1006 | {\r | |
1a63ec8f | 1007 | F1394_DEVICE_PATH *DevicePath_F1394;\r |
a405b86d | 1008 | CHAR16 Buffer[20];\r |
1009 | \r | |
1010 | ASSERT(DevicePathNode != NULL);\r | |
1011 | ASSERT(MappingItem != NULL);\r | |
1012 | \r | |
1a63ec8f | 1013 | DevicePath_F1394 = (F1394_DEVICE_PATH *) DevicePathNode;\r |
1014 | UnicodeSPrint (Buffer, 0, L"%lx", DevicePath_F1394->Guid);\r | |
a405b86d | 1015 | AppendCSDStr (MappingItem, Buffer);\r |
1016 | }\r | |
1017 | \r | |
1018 | /**\r | |
1019 | If the node is floppy type then populate the MappingItem.\r | |
1020 | \r | |
1021 | @param[in] DevicePathNode The node to get info on.\r | |
1022 | @param[in] MappingItem The info item to populate.\r | |
41089802 | 1023 | @param[in] DevicePath Ignored.\r |
a405b86d | 1024 | **/\r |
1025 | VOID\r | |
1026 | EFIAPI\r | |
1027 | DevPathSerialAcpi (\r | |
1028 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
0db3fade | 1029 | IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
1030 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
a405b86d | 1031 | )\r |
1032 | {\r | |
1033 | ACPI_HID_DEVICE_PATH *Acpi;\r | |
1034 | \r | |
1035 | ASSERT(DevicePathNode != NULL);\r | |
1036 | ASSERT(MappingItem != NULL);\r | |
1037 | \r | |
1038 | Acpi = (ACPI_HID_DEVICE_PATH *) DevicePathNode;\r | |
1039 | if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {\r | |
1040 | if (EISA_ID_TO_NUM (Acpi->HID) == 0x0604) {\r | |
1a63ec8f | 1041 | MappingItem->Mtd = MTDTypeFloppy;\r |
a405b86d | 1042 | AppendCSDNum (MappingItem, Acpi->UID);\r |
1043 | }\r | |
1044 | }\r | |
1045 | }\r | |
1046 | \r | |
1047 | /**\r | |
1048 | Empty function used for unknown devices.\r | |
1049 | \r | |
1a63ec8f | 1050 | @param[in] DevicePathNode Ignored.\r |
1051 | @param[in] MappingItem Ignored.\r | |
41089802 | 1052 | @param[in] DevicePath Ignored.\r |
1a63ec8f | 1053 | \r |
a405b86d | 1054 | Does nothing.\r |
1055 | **/\r | |
1056 | VOID\r | |
1057 | EFIAPI\r | |
1058 | DevPathSerialDefault (\r | |
1059 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
0db3fade | 1060 | IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r |
1061 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
a405b86d | 1062 | )\r |
1063 | {\r | |
1a63ec8f | 1064 | return;\r |
a405b86d | 1065 | }\r |
1066 | \r | |
1067 | DEV_PATH_CONSIST_MAPPING_TABLE DevPathConsistMappingTable[] = {\r | |
ce68d3bc SZ |
1068 | {\r |
1069 | HARDWARE_DEVICE_PATH,\r | |
1070 | HW_PCI_DP,\r | |
1071 | DevPathSerialDefault,\r | |
1072 | DevPathComparePci\r | |
1073 | },\r | |
1074 | {\r | |
1075 | ACPI_DEVICE_PATH,\r | |
1076 | ACPI_DP,\r | |
1077 | DevPathSerialAcpi,\r | |
1078 | DevPathCompareAcpi\r | |
1079 | },\r | |
1080 | {\r | |
1081 | MESSAGING_DEVICE_PATH,\r | |
1082 | MSG_ATAPI_DP,\r | |
1083 | DevPathSerialAtapi,\r | |
1084 | DevPathCompareDefault\r | |
1085 | },\r | |
1086 | {\r | |
1087 | MESSAGING_DEVICE_PATH,\r | |
1088 | MSG_SCSI_DP,\r | |
1089 | DevPathSerialScsi,\r | |
1090 | DevPathCompareDefault\r | |
1091 | },\r | |
1092 | {\r | |
1093 | MESSAGING_DEVICE_PATH,\r | |
1094 | MSG_FIBRECHANNEL_DP,\r | |
1095 | DevPathSerialFibre,\r | |
1096 | DevPathCompareDefault\r | |
1097 | },\r | |
1098 | {\r | |
1099 | MESSAGING_DEVICE_PATH,\r | |
1100 | MSG_1394_DP,\r | |
1101 | DevPathSerial1394,\r | |
1102 | DevPathCompareDefault\r | |
1103 | },\r | |
1104 | {\r | |
1105 | MESSAGING_DEVICE_PATH,\r | |
1106 | MSG_USB_DP,\r | |
1107 | DevPathSerialUsb,\r | |
1108 | DevPathCompareDefault\r | |
1109 | },\r | |
1110 | {\r | |
1111 | MESSAGING_DEVICE_PATH,\r | |
1112 | MSG_I2O_DP,\r | |
1113 | DevPathSerialI2O,\r | |
1114 | DevPathCompareDefault\r | |
1115 | },\r | |
1116 | {\r | |
1117 | MESSAGING_DEVICE_PATH,\r | |
1118 | MSG_MAC_ADDR_DP,\r | |
1119 | DevPathSerialMacAddr,\r | |
1120 | DevPathCompareDefault\r | |
1121 | },\r | |
1122 | {\r | |
1123 | MESSAGING_DEVICE_PATH,\r | |
1124 | MSG_IPv4_DP,\r | |
1125 | DevPathSerialIPv4,\r | |
1126 | DevPathCompareDefault\r | |
1127 | },\r | |
1128 | {\r | |
1129 | MESSAGING_DEVICE_PATH,\r | |
1130 | MSG_IPv6_DP,\r | |
1131 | DevPathSerialIPv6,\r | |
1132 | DevPathCompareDefault\r | |
1133 | },\r | |
1134 | {\r | |
1135 | MESSAGING_DEVICE_PATH,\r | |
1136 | MSG_INFINIBAND_DP,\r | |
1137 | DevPathSerialInfiniBand,\r | |
1138 | DevPathCompareDefault\r | |
1139 | },\r | |
1140 | {\r | |
1141 | MESSAGING_DEVICE_PATH,\r | |
1142 | MSG_UART_DP,\r | |
1143 | DevPathSerialUart,\r | |
1144 | DevPathCompareDefault\r | |
1145 | },\r | |
1146 | {\r | |
1147 | MESSAGING_DEVICE_PATH,\r | |
1148 | MSG_VENDOR_DP,\r | |
1149 | DevPathSerialVendor,\r | |
1150 | DevPathCompareDefault\r | |
1151 | },\r | |
1152 | {\r | |
1153 | MESSAGING_DEVICE_PATH,\r | |
1154 | MSG_DEVICE_LOGICAL_UNIT_DP,\r | |
1155 | DevPathSerialLun,\r | |
1156 | DevPathCompareDefault\r | |
1157 | },\r | |
1158 | {\r | |
1159 | MESSAGING_DEVICE_PATH,\r | |
1160 | MSG_SATA_DP,\r | |
1161 | DevPathSerialSata,\r | |
1162 | DevPathCompareDefault\r | |
1163 | },\r | |
1164 | {\r | |
1165 | MESSAGING_DEVICE_PATH,\r | |
1166 | MSG_ISCSI_DP,\r | |
1167 | DevPathSerialIScsi,\r | |
1168 | DevPathCompareDefault\r | |
1169 | },\r | |
1170 | {\r | |
1171 | MEDIA_DEVICE_PATH,\r | |
1172 | MEDIA_HARDDRIVE_DP,\r | |
1173 | DevPathSerialHardDrive,\r | |
1174 | DevPathCompareDefault\r | |
1175 | },\r | |
1176 | {\r | |
1177 | MEDIA_DEVICE_PATH,\r | |
1178 | MEDIA_CDROM_DP,\r | |
1179 | DevPathSerialCdRom,\r | |
1180 | DevPathCompareDefault\r | |
1181 | },\r | |
1182 | {\r | |
1183 | MEDIA_DEVICE_PATH,\r | |
1184 | MEDIA_VENDOR_DP,\r | |
1185 | DevPathSerialVendor,\r | |
1186 | DevPathCompareDefault\r | |
1187 | },\r | |
1188 | {\r | |
1189 | 0,\r | |
1190 | 0,\r | |
1191 | NULL,\r | |
1192 | NULL\r | |
1193 | }\r | |
a405b86d | 1194 | };\r |
1195 | \r | |
1196 | /**\r | |
1197 | Function to determine if a device path node is Hi or not.\r | |
1198 | \r | |
1199 | @param[in] DevicePathNode The node to check.\r | |
1200 | \r | |
1a63ec8f | 1201 | @retval TRUE The node is Hi.\r |
1202 | @retval FALSE The node is not Hi.\r | |
a405b86d | 1203 | **/\r |
1204 | BOOLEAN\r | |
1205 | EFIAPI\r | |
1206 | IsHIDevicePathNode (\r | |
1207 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode\r | |
1208 | )\r | |
1209 | {\r | |
1210 | ACPI_HID_DEVICE_PATH *Acpi;\r | |
1211 | \r | |
1212 | ASSERT(DevicePathNode != NULL);\r | |
1213 | \r | |
1214 | if (DevicePathNode->Type == HARDWARE_DEVICE_PATH) {\r | |
1215 | return TRUE;\r | |
1216 | }\r | |
1217 | \r | |
1218 | if (DevicePathNode->Type == ACPI_DEVICE_PATH) {\r | |
1219 | Acpi = (ACPI_HID_DEVICE_PATH *) DevicePathNode;\r | |
1220 | switch (EISA_ID_TO_NUM (Acpi->HID)) {\r | |
1221 | case 0x0301:\r | |
1222 | case 0x0401:\r | |
1223 | case 0x0501:\r | |
1224 | case 0x0604:\r | |
1225 | return FALSE;\r | |
1226 | }\r | |
1227 | \r | |
1228 | return TRUE;\r | |
1229 | }\r | |
1230 | \r | |
1231 | return FALSE;\r | |
1232 | }\r | |
1233 | \r | |
1234 | /**\r | |
1a63ec8f | 1235 | Function to convert a standard device path structure into a Hi version.\r |
a405b86d | 1236 | \r |
1237 | @param[in] DevicePath The device path to convert.\r | |
1238 | \r | |
1a63ec8f | 1239 | @return the device path portion that is Hi.\r |
a405b86d | 1240 | **/\r |
1241 | EFI_DEVICE_PATH_PROTOCOL *\r | |
1242 | EFIAPI\r | |
1243 | GetHIDevicePath (\r | |
1244 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
1245 | )\r | |
1246 | {\r | |
1247 | UINTN NonHIDevicePathNodeCount;\r | |
1248 | UINTN Index;\r | |
1249 | EFI_DEV_PATH Node;\r | |
1250 | EFI_DEVICE_PATH_PROTOCOL *HIDevicePath;\r | |
1251 | EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r | |
1252 | \r | |
1253 | ASSERT(DevicePath != NULL);\r | |
1254 | \r | |
1255 | NonHIDevicePathNodeCount = 0;\r | |
1256 | \r | |
1a63ec8f | 1257 | HIDevicePath = AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL));\r |
a405b86d | 1258 | SetDevicePathEndNode (HIDevicePath);\r |
1259 | \r | |
1260 | Node.DevPath.Type = END_DEVICE_PATH_TYPE;\r | |
1261 | Node.DevPath.SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE;\r | |
1262 | Node.DevPath.Length[0] = (UINT8)sizeof (EFI_DEVICE_PATH_PROTOCOL);\r | |
1263 | Node.DevPath.Length[1] = 0;\r | |
1264 | \r | |
1265 | while (!IsDevicePathEnd (DevicePath)) {\r | |
1266 | if (IsHIDevicePathNode (DevicePath)) {\r | |
1267 | for (Index = 0; Index < NonHIDevicePathNodeCount; Index++) {\r | |
1268 | TempDevicePath = AppendDevicePathNode (HIDevicePath, &Node.DevPath);\r | |
1269 | FreePool (HIDevicePath);\r | |
1270 | HIDevicePath = TempDevicePath;\r | |
1271 | }\r | |
1272 | \r | |
1273 | TempDevicePath = AppendDevicePathNode (HIDevicePath, DevicePath);\r | |
1274 | FreePool (HIDevicePath);\r | |
1275 | HIDevicePath = TempDevicePath;\r | |
1276 | } else {\r | |
1277 | NonHIDevicePathNodeCount++;\r | |
1278 | }\r | |
1279 | //\r | |
1280 | // Next device path node\r | |
1281 | //\r | |
1282 | DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) NextDevicePathNode (DevicePath);\r | |
1283 | }\r | |
1284 | \r | |
1285 | return HIDevicePath;\r | |
1286 | }\r | |
1287 | \r | |
1288 | /**\r | |
1289 | Function to walk the device path looking for a dumpable node.\r | |
1290 | \r | |
1291 | @param[in] MappingItem The Item to fill with data.\r | |
1292 | @param[in] DevicePath The path of the item to get data on.\r | |
1293 | \r | |
1294 | @return EFI_SUCCESS Always returns success.\r | |
1295 | **/\r | |
1296 | EFI_STATUS\r | |
1297 | EFIAPI\r | |
1298 | GetDeviceConsistMappingInfo (\r | |
1299 | IN DEVICE_CONSIST_MAPPING_INFO *MappingItem,\r | |
1300 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
1301 | )\r | |
1302 | {\r | |
41089802 | 1303 | SERIAL_DECODE_FUNCTION SerialFun;\r |
0db3fade | 1304 | UINTN Index;\r |
1305 | EFI_DEVICE_PATH_PROTOCOL *OriginalDevicePath;\r | |
a405b86d | 1306 | \r |
1307 | ASSERT(DevicePath != NULL);\r | |
1308 | ASSERT(MappingItem != NULL);\r | |
1309 | \r | |
1a63ec8f | 1310 | SetMem (&MappingItem->Csd, sizeof (POOL_PRINT), 0);\r |
0db3fade | 1311 | OriginalDevicePath = DevicePath;\r |
a405b86d | 1312 | \r |
1313 | while (!IsDevicePathEnd (DevicePath)) {\r | |
1314 | //\r | |
0db3fade | 1315 | // Find the handler to dump this device path node and\r |
1316 | // initialize with generic function in case nothing is found\r | |
a405b86d | 1317 | //\r |
0db3fade | 1318 | for (SerialFun = DevPathSerialDefault, Index = 0; DevPathConsistMappingTable[Index].SerialFun != NULL; Index += 1) {\r |
a405b86d | 1319 | \r |
1320 | if (DevicePathType (DevicePath) == DevPathConsistMappingTable[Index].Type &&\r | |
1321 | DevicePathSubType (DevicePath) == DevPathConsistMappingTable[Index].SubType\r | |
1322 | ) {\r | |
1323 | SerialFun = DevPathConsistMappingTable[Index].SerialFun;\r | |
1324 | break;\r | |
1325 | }\r | |
1326 | }\r | |
a405b86d | 1327 | \r |
0db3fade | 1328 | SerialFun (DevicePath, MappingItem, OriginalDevicePath);\r |
a405b86d | 1329 | \r |
1330 | //\r | |
1331 | // Next device path node\r | |
1332 | //\r | |
1333 | DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) NextDevicePathNode (DevicePath);\r | |
1334 | }\r | |
1335 | \r | |
1336 | return EFI_SUCCESS;\r | |
1337 | }\r | |
1338 | \r | |
1339 | /**\r | |
1340 | Function to initialize the table for creating consistent map names.\r | |
1341 | \r | |
1342 | @param[out] Table The pointer to pointer to pointer to DevicePathProtocol object.\r | |
1343 | \r | |
1344 | @retval EFI_SUCCESS The table was created successfully.\r | |
1345 | **/\r | |
1346 | EFI_STATUS\r | |
1347 | EFIAPI\r | |
1348 | ShellCommandConsistMappingInitialize (\r | |
1349 | OUT EFI_DEVICE_PATH_PROTOCOL ***Table\r | |
1350 | )\r | |
1351 | {\r | |
1352 | EFI_HANDLE *HandleBuffer;\r | |
1353 | UINTN HandleNum;\r | |
1354 | UINTN HandleLoop;\r | |
1355 | EFI_DEVICE_PATH_PROTOCOL **TempTable;\r | |
1356 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
1357 | EFI_DEVICE_PATH_PROTOCOL *HIDevicePath;\r | |
1358 | UINTN Index;\r | |
1359 | EFI_STATUS Status;\r | |
1360 | \r | |
1361 | HandleBuffer = NULL;\r | |
1362 | \r | |
1363 | Status = gBS->LocateHandleBuffer (\r | |
1364 | AllHandles,\r | |
1365 | NULL,\r | |
1366 | NULL,\r | |
1367 | &HandleNum,\r | |
1368 | &HandleBuffer\r | |
1369 | );\r | |
1370 | ASSERT_EFI_ERROR(Status);\r | |
1371 | \r | |
1372 | TempTable = AllocateZeroPool ((HandleNum + 1) * sizeof (EFI_DEVICE_PATH_PROTOCOL *));\r | |
1373 | if (TempTable == NULL) {\r | |
1374 | return EFI_OUT_OF_RESOURCES;\r | |
1375 | }\r | |
1376 | \r | |
1377 | for (HandleLoop = 0 ; HandleLoop < HandleNum ; HandleLoop++) {\r | |
1378 | DevicePath = DevicePathFromHandle (HandleBuffer[HandleLoop]);\r | |
1379 | if (DevicePath == NULL) {\r | |
1380 | continue;\r | |
1381 | }\r | |
1382 | \r | |
1383 | HIDevicePath = GetHIDevicePath (DevicePath);\r | |
1384 | if (HIDevicePath == NULL) {\r | |
1385 | continue;\r | |
1386 | }\r | |
1387 | \r | |
1388 | for (Index = 0; TempTable[Index] != NULL; Index++) {\r | |
1389 | if (DevicePathCompare (&TempTable[Index], &HIDevicePath) == 0) {\r | |
1390 | FreePool (HIDevicePath);\r | |
1391 | break;\r | |
1392 | }\r | |
1393 | }\r | |
1394 | \r | |
1395 | if (TempTable[Index] == NULL) {\r | |
1396 | TempTable[Index] = HIDevicePath;\r | |
1397 | }\r | |
1398 | }\r | |
1399 | \r | |
1400 | for (Index = 0; TempTable[Index] != NULL; Index++);\r | |
1401 | PerformQuickSort(TempTable, Index, sizeof(EFI_DEVICE_PATH_PROTOCOL*), DevicePathCompare);\r | |
1402 | *Table = TempTable;\r | |
1403 | \r | |
1404 | if (HandleBuffer != NULL) {\r | |
1405 | FreePool (HandleBuffer);\r | |
1406 | }\r | |
1407 | \r | |
1408 | return EFI_SUCCESS;\r | |
1409 | }\r | |
1410 | \r | |
1411 | /**\r | |
1412 | Function to uninitialize the table for creating consistent map names.\r | |
1413 | \r | |
1414 | The parameter must have been received from ShellCommandConsistMappingInitialize.\r | |
1415 | \r | |
1416 | @param[out] Table The pointer to pointer to DevicePathProtocol object.\r | |
1417 | \r | |
1418 | @retval EFI_SUCCESS The table was deleted successfully.\r | |
1419 | **/\r | |
1420 | EFI_STATUS\r | |
1421 | EFIAPI\r | |
1422 | ShellCommandConsistMappingUnInitialize (\r | |
1423 | EFI_DEVICE_PATH_PROTOCOL **Table\r | |
1424 | )\r | |
1425 | {\r | |
1426 | UINTN Index;\r | |
1427 | \r | |
1428 | ASSERT(Table != NULL);\r | |
1429 | \r | |
1430 | for (Index = 0; Table[Index] != NULL; Index++) {\r | |
1431 | FreePool (Table[Index]);\r | |
1432 | }\r | |
1433 | \r | |
1434 | FreePool (Table);\r | |
1435 | return EFI_SUCCESS;\r | |
1436 | }\r | |
1437 | \r | |
1438 | /**\r | |
e26d7b59 | 1439 | Create a consistent mapped name for the device specified by DevicePath\r |
a405b86d | 1440 | based on the Table.\r |
1441 | \r | |
e26d7b59 | 1442 | This must be called after ShellCommandConsistMappingInitialize() and\r |
a405b86d | 1443 | before ShellCommandConsistMappingUnInitialize() is called.\r |
1444 | \r | |
1a63ec8f | 1445 | @param[in] DevicePath The pointer to the dev path for the device.\r |
a405b86d | 1446 | @param[in] Table The Table of mapping information.\r |
1447 | \r | |
1448 | @retval NULL A consistent mapped name could not be created.\r | |
1449 | @return A pointer to a string allocated from pool with the device name.\r | |
1450 | **/\r | |
1451 | CHAR16 *\r | |
1452 | EFIAPI\r | |
1453 | ShellCommandConsistMappingGenMappingName (\r | |
1a63ec8f | 1454 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r |
1455 | IN EFI_DEVICE_PATH_PROTOCOL **Table\r | |
a405b86d | 1456 | )\r |
1457 | {\r | |
1458 | POOL_PRINT Str;\r | |
1459 | DEVICE_CONSIST_MAPPING_INFO MappingInfo;\r | |
1460 | EFI_DEVICE_PATH_PROTOCOL *HIDevicePath;\r | |
1461 | UINTN Index;\r | |
1462 | UINTN NewSize;\r | |
1463 | \r | |
1464 | ASSERT(DevicePath != NULL);\r | |
1465 | ASSERT(Table != NULL);\r | |
1466 | \r | |
1467 | HIDevicePath = GetHIDevicePath (DevicePath);\r | |
1468 | if (HIDevicePath == NULL) {\r | |
1469 | return NULL;\r | |
1470 | }\r | |
1471 | \r | |
1472 | for (Index = 0; Table[Index] != NULL; Index++) {\r | |
1473 | if (DevicePathCompare (&Table[Index], &HIDevicePath) == 0) {\r | |
1474 | break;\r | |
1475 | }\r | |
1476 | }\r | |
1477 | \r | |
1478 | FreePool (HIDevicePath);\r | |
1479 | if (Table[Index] == NULL) {\r | |
1480 | return NULL;\r | |
1481 | }\r | |
1482 | \r | |
1a63ec8f | 1483 | MappingInfo.Hi = Index;\r |
1484 | MappingInfo.Mtd = MTDTypeUnknown;\r | |
a405b86d | 1485 | MappingInfo.Digital = FALSE;\r |
1486 | \r | |
1487 | GetDeviceConsistMappingInfo (&MappingInfo, DevicePath);\r | |
1488 | \r | |
1489 | SetMem (&Str, sizeof (Str), 0);\r | |
1490 | for (Index = 0; mMTDName[Index].MTDType != MTDTypeEnd; Index++) {\r | |
1a63ec8f | 1491 | if (MappingInfo.Mtd == mMTDName[Index].MTDType) {\r |
a405b86d | 1492 | break;\r |
1493 | }\r | |
1494 | }\r | |
1495 | \r | |
1496 | if (mMTDName[Index].MTDType != MTDTypeEnd) {\r | |
1497 | CatPrint (&Str, L"%s", mMTDName[Index].Name);\r | |
1498 | }\r | |
1499 | \r | |
1a63ec8f | 1500 | CatPrint (&Str, L"%d", (UINTN) MappingInfo.Hi);\r |
1501 | if (MappingInfo.Csd.Str != NULL) {\r | |
1502 | CatPrint (&Str, L"%s", MappingInfo.Csd.Str);\r | |
1503 | FreePool (MappingInfo.Csd.Str);\r | |
a405b86d | 1504 | }\r |
1505 | \r | |
1506 | if (Str.Str != NULL) {\r | |
1507 | CatPrint (&Str, L":");\r | |
1508 | }\r | |
1509 | \r | |
1510 | NewSize = (Str.Len + 1) * sizeof (CHAR16);\r | |
1511 | Str.Str = ReallocatePool (Str.Len, NewSize, Str.Str);\r | |
e53bf79d | 1512 | if (Str.Str == NULL) {\r |
1513 | return (NULL);\r | |
1514 | }\r | |
a405b86d | 1515 | Str.Str[Str.Len] = CHAR_NULL;\r |
1516 | return Str.Str;\r | |
1517 | }\r | |
1518 | \r | |
1519 | /**\r | |
1520 | Function to search the list of mappings for the node on the list based on the key.\r | |
1521 | \r | |
1522 | @param[in] MapKey String Key to search for on the map\r | |
1523 | \r | |
1524 | @return the node on the list.\r | |
1525 | **/\r | |
1526 | SHELL_MAP_LIST *\r | |
1527 | EFIAPI\r | |
1528 | ShellCommandFindMapItem (\r | |
1529 | IN CONST CHAR16 *MapKey\r | |
1530 | )\r | |
1531 | {\r | |
1532 | SHELL_MAP_LIST *MapListItem;\r | |
1533 | \r | |
1534 | for ( MapListItem = (SHELL_MAP_LIST *)GetFirstNode(&gShellMapList.Link)\r | |
1535 | ; !IsNull(&gShellMapList.Link, &MapListItem->Link)\r | |
1536 | ; MapListItem = (SHELL_MAP_LIST *)GetNextNode(&gShellMapList.Link, &MapListItem->Link)\r | |
1537 | ){\r | |
1538 | if (gUnicodeCollation->StriColl(gUnicodeCollation,MapListItem->MapName,(CHAR16*)MapKey) == 0) {\r | |
1539 | return (MapListItem);\r | |
1540 | }\r | |
1541 | }\r | |
1542 | return (NULL);\r | |
1543 | }\r | |
1544 | \r | |
1545 | \r |