]>
Commit | Line | Data |
---|---|---|
32465d9a DB |
1 | /** @file\r |
2 | The device manager reference implementation\r | |
3 | \r | |
d1102dba | 4 | Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r |
32465d9a DB |
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 | \r | |
15 | #include "DeviceManager.h"\r | |
16 | \r | |
17 | DEVICE_MANAGER_CALLBACK_DATA gDeviceManagerPrivate = {\r | |
18 | DEVICE_MANAGER_CALLBACK_DATA_SIGNATURE,\r | |
19 | NULL,\r | |
20 | NULL,\r | |
21 | {\r | |
22 | DeviceManagerExtractConfig,\r | |
23 | DeviceManagerRouteConfig,\r | |
24 | DeviceManagerCallback\r | |
25 | }\r | |
26 | };\r | |
27 | \r | |
28 | #define MAX_MAC_ADDRESS_NODE_LIST_LEN 10\r | |
29 | \r | |
30 | EFI_GUID mDeviceManagerGuid = DEVICE_MANAGER_FORMSET_GUID;\r | |
31 | \r | |
32 | //\r | |
33 | // Which Mac Address string is select\r | |
34 | // it will decide what menu need to show in the NETWORK_DEVICE_FORM_ID form.\r | |
35 | //\r | |
36 | EFI_STRING mSelectedMacAddrString;\r | |
37 | \r | |
38 | //\r | |
39 | // The Mac Address show in the NETWORK_DEVICE_LIST_FORM_ID\r | |
40 | //\r | |
41 | MAC_ADDRESS_NODE_LIST mMacDeviceList;\r | |
42 | \r | |
43 | HII_VENDOR_DEVICE_PATH mDeviceManagerHiiVendorDevicePath = {\r | |
44 | {\r | |
45 | {\r | |
46 | HARDWARE_DEVICE_PATH,\r | |
47 | HW_VENDOR_DP,\r | |
48 | {\r | |
49 | (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r | |
50 | (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r | |
51 | }\r | |
52 | },\r | |
53 | //\r | |
54 | // {102579A0-3686-466e-ACD8-80C087044F4A}\r | |
55 | //\r | |
56 | { 0x102579a0, 0x3686, 0x466e, { 0xac, 0xd8, 0x80, 0xc0, 0x87, 0x4, 0x4f, 0x4a } }\r | |
57 | },\r | |
58 | {\r | |
59 | END_DEVICE_PATH_TYPE,\r | |
60 | END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
d1102dba | 61 | {\r |
32465d9a DB |
62 | (UINT8) (END_DEVICE_PATH_LENGTH),\r |
63 | (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r | |
64 | }\r | |
65 | }\r | |
66 | };\r | |
67 | \r | |
68 | /**\r | |
69 | Extract device path for given HII handle and class guid.\r | |
70 | \r | |
71 | @param Handle The HII handle.\r | |
72 | \r | |
73 | @retval NULL Fail to get the device path string.\r | |
74 | @return PathString Get the device path string.\r | |
75 | \r | |
76 | **/\r | |
77 | CHAR16 *\r | |
78 | DmExtractDevicePathFromHiiHandle (\r | |
79 | IN EFI_HII_HANDLE Handle\r | |
80 | )\r | |
81 | {\r | |
82 | EFI_STATUS Status;\r | |
83 | EFI_HANDLE DriverHandle;\r | |
84 | \r | |
85 | ASSERT (Handle != NULL);\r | |
86 | \r | |
87 | if (Handle == NULL) {\r | |
88 | return NULL;\r | |
89 | }\r | |
90 | \r | |
91 | Status = gHiiDatabase->GetPackageListHandle (gHiiDatabase, Handle, &DriverHandle);\r | |
92 | if (EFI_ERROR (Status)) {\r | |
93 | return NULL;\r | |
94 | }\r | |
95 | //\r | |
96 | // Get device path string.\r | |
97 | //\r | |
98 | return ConvertDevicePathToText(DevicePathFromHandle (DriverHandle), FALSE, FALSE);\r | |
99 | }\r | |
100 | \r | |
101 | /**\r | |
102 | Get the mac address string from the device path.\r | |
103 | if the device path has the vlan, get the vanid also.\r | |
d1102dba LG |
104 | \r |
105 | @param MacAddressNode Device path begin with mac address\r | |
32465d9a DB |
106 | @param PBuffer Output string buffer contain mac address.\r |
107 | \r | |
108 | **/\r | |
d1102dba | 109 | BOOLEAN\r |
32465d9a DB |
110 | GetMacAddressString(\r |
111 | IN MAC_ADDR_DEVICE_PATH *MacAddressNode,\r | |
112 | OUT CHAR16 **PBuffer\r | |
113 | )\r | |
114 | {\r | |
115 | UINTN HwAddressSize;\r | |
116 | UINTN Index;\r | |
117 | UINT8 *HwAddress;\r | |
118 | EFI_DEVICE_PATH_PROTOCOL *Node;\r | |
119 | UINT16 VlanId;\r | |
120 | CHAR16 *String;\r | |
121 | UINTN BufferLen;\r | |
122 | \r | |
123 | VlanId = 0;\r | |
124 | String = NULL;\r | |
125 | ASSERT(MacAddressNode != NULL);\r | |
126 | \r | |
127 | HwAddressSize = sizeof (EFI_MAC_ADDRESS);\r | |
128 | if (MacAddressNode->IfType == 0x01 || MacAddressNode->IfType == 0x00) {\r | |
129 | HwAddressSize = 6;\r | |
130 | }\r | |
131 | \r | |
132 | //\r | |
133 | // The output format is MAC:XX:XX:XX:...\XXXX\r | |
134 | // The size is the Number size + ":" size + Vlan size(\XXXX) + End\r | |
135 | //\r | |
136 | BufferLen = (4 + 2 * HwAddressSize + (HwAddressSize - 1) + 5 + 1) * sizeof (CHAR16);\r | |
137 | String = AllocateZeroPool (BufferLen);\r | |
138 | if (String == NULL) {\r | |
139 | return FALSE;\r | |
140 | }\r | |
141 | \r | |
142 | *PBuffer = String;\r | |
143 | StrCpyS(String, BufferLen / sizeof (CHAR16), L"MAC:");\r | |
144 | String += 4;\r | |
d1102dba | 145 | \r |
32465d9a DB |
146 | //\r |
147 | // Convert the MAC address into a unicode string.\r | |
148 | //\r | |
149 | HwAddress = &MacAddressNode->MacAddress.Addr[0];\r | |
150 | for (Index = 0; Index < HwAddressSize; Index++) {\r | |
9f4048f7 HW |
151 | UnicodeValueToStringS (\r |
152 | String,\r | |
153 | BufferLen - ((UINTN)String - (UINTN)*PBuffer),\r | |
154 | PREFIX_ZERO | RADIX_HEX,\r | |
155 | *(HwAddress++),\r | |
156 | 2\r | |
157 | );\r | |
158 | String += StrnLenS (String, (BufferLen - ((UINTN)String - (UINTN)*PBuffer)) / sizeof (CHAR16));\r | |
32465d9a DB |
159 | if (Index < HwAddressSize - 1) {\r |
160 | *String++ = L':';\r | |
161 | }\r | |
162 | }\r | |
163 | \r | |
164 | //\r | |
165 | // If VLAN is configured, it will need extra 5 characters like "\0005".\r | |
166 | // Plus one unicode character for the null-terminator.\r | |
167 | //\r | |
168 | Node = (EFI_DEVICE_PATH_PROTOCOL *)MacAddressNode;\r | |
169 | while (!IsDevicePathEnd (Node)) {\r | |
170 | if (Node->Type == MESSAGING_DEVICE_PATH && Node->SubType == MSG_VLAN_DP) {\r | |
171 | VlanId = ((VLAN_DEVICE_PATH *) Node)->VlanId;\r | |
172 | }\r | |
173 | Node = NextDevicePathNode (Node);\r | |
174 | }\r | |
175 | \r | |
176 | if (VlanId != 0) {\r | |
177 | *String++ = L'\\';\r | |
9f4048f7 HW |
178 | UnicodeValueToStringS (\r |
179 | String,\r | |
180 | BufferLen - ((UINTN)String - (UINTN)*PBuffer),\r | |
181 | PREFIX_ZERO | RADIX_HEX,\r | |
182 | VlanId,\r | |
183 | 4\r | |
184 | );\r | |
185 | String += StrnLenS (String, (BufferLen - ((UINTN)String - (UINTN)*PBuffer)) / sizeof (CHAR16));\r | |
32465d9a DB |
186 | }\r |
187 | \r | |
188 | //\r | |
189 | // Null terminate the Unicode string\r | |
190 | //\r | |
191 | *String = L'\0';\r | |
192 | \r | |
193 | return TRUE;\r | |
194 | }\r | |
195 | \r | |
196 | /**\r | |
197 | Save question id and prompt id to the mac device list.\r | |
198 | If the same mac address has saved yet, no need to add more.\r | |
199 | \r | |
200 | @param MacAddrString Mac address string.\r | |
201 | \r | |
202 | @retval EFI_SUCCESS Add the item is successful.\r | |
203 | @return Other values if failed to Add the item.\r | |
204 | **/\r | |
d1102dba | 205 | BOOLEAN\r |
32465d9a DB |
206 | AddIdToMacDeviceList (\r |
207 | IN EFI_STRING MacAddrString\r | |
208 | )\r | |
209 | {\r | |
210 | MENU_INFO_ITEM *TempDeviceList;\r | |
211 | UINTN Index;\r | |
212 | EFI_STRING StoredString;\r | |
213 | EFI_STRING_ID PromptId;\r | |
214 | EFI_HII_HANDLE HiiHandle;\r | |
215 | \r | |
216 | HiiHandle = gDeviceManagerPrivate.HiiHandle;\r | |
217 | TempDeviceList = NULL;\r | |
218 | \r | |
219 | for (Index = 0; Index < mMacDeviceList.CurListLen; Index ++) {\r | |
220 | StoredString = HiiGetString (HiiHandle, mMacDeviceList.NodeList[Index].PromptId, NULL);\r | |
221 | if (StoredString == NULL) {\r | |
222 | return FALSE;\r | |
223 | }\r | |
224 | \r | |
225 | //\r | |
226 | // Already has save the same mac address to the list.\r | |
227 | //\r | |
228 | if (StrCmp (MacAddrString, StoredString) == 0) {\r | |
229 | return FALSE;\r | |
230 | }\r | |
231 | }\r | |
232 | \r | |
233 | PromptId = HiiSetString(HiiHandle, 0, MacAddrString, NULL);\r | |
234 | //\r | |
235 | // If not in the list, save it.\r | |
236 | //\r | |
237 | if (mMacDeviceList.MaxListLen > mMacDeviceList.CurListLen + 1) {\r | |
238 | mMacDeviceList.NodeList[mMacDeviceList.CurListLen].PromptId = PromptId;\r | |
239 | mMacDeviceList.NodeList[mMacDeviceList.CurListLen].QuestionId = (EFI_QUESTION_ID) (mMacDeviceList.CurListLen + NETWORK_DEVICE_LIST_KEY_OFFSET);\r | |
240 | } else {\r | |
241 | mMacDeviceList.MaxListLen += MAX_MAC_ADDRESS_NODE_LIST_LEN;\r | |
242 | if (mMacDeviceList.CurListLen != 0) {\r | |
469293f8 JW |
243 | TempDeviceList = ReallocatePool (\r |
244 | sizeof (MENU_INFO_ITEM) * mMacDeviceList.CurListLen,\r | |
245 | sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen,\r | |
246 | mMacDeviceList.NodeList\r | |
247 | );\r | |
32465d9a DB |
248 | } else {\r |
249 | TempDeviceList = (MENU_INFO_ITEM *)AllocatePool (sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen);\r | |
250 | }\r | |
251 | \r | |
252 | if (TempDeviceList == NULL) {\r | |
253 | return FALSE;\r | |
254 | }\r | |
d1102dba | 255 | TempDeviceList[mMacDeviceList.CurListLen].PromptId = PromptId;\r |
32465d9a DB |
256 | TempDeviceList[mMacDeviceList.CurListLen].QuestionId = (EFI_QUESTION_ID) (mMacDeviceList.CurListLen + NETWORK_DEVICE_LIST_KEY_OFFSET);\r |
257 | \r | |
32465d9a DB |
258 | mMacDeviceList.NodeList = TempDeviceList;\r |
259 | }\r | |
260 | mMacDeviceList.CurListLen ++;\r | |
261 | \r | |
262 | return TRUE;\r | |
263 | }\r | |
264 | \r | |
265 | /**\r | |
266 | Check the devcie path, try to find whether it has mac address path.\r | |
267 | \r | |
268 | In this function, first need to check whether this path has mac address path.\r | |
269 | second, when the mac address device path has find, also need to deicide whether\r | |
270 | need to add this mac address relate info to the menu.\r | |
271 | \r | |
272 | @param *Node Input device which need to be check.\r | |
273 | @param NextShowFormId FormId Which need to be show.\r | |
274 | @param *NeedAddItem Whether need to add the menu in the network device list.\r | |
275 | \r | |
276 | @retval TRUE Has mac address device path.\r | |
277 | @retval FALSE NOT Has mac address device path.\r | |
278 | \r | |
279 | **/\r | |
280 | BOOLEAN\r | |
281 | IsMacAddressDevicePath (\r | |
282 | IN VOID *Node,\r | |
283 | IN EFI_FORM_ID NextShowFormId,\r | |
284 | OUT BOOLEAN *NeedAddItem\r | |
285 | )\r | |
286 | {\r | |
287 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
288 | CHAR16 *Buffer;\r | |
289 | BOOLEAN ReturnVal;\r | |
290 | \r | |
291 | ASSERT (Node != NULL);\r | |
292 | *NeedAddItem = FALSE;\r | |
293 | ReturnVal = FALSE;\r | |
294 | Buffer = NULL;\r | |
295 | \r | |
296 | DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Node;\r | |
297 | \r | |
298 | //\r | |
299 | // find the partition device path node\r | |
300 | //\r | |
301 | while (!IsDevicePathEnd (DevicePath)) {\r | |
302 | if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&\r | |
303 | (DevicePathSubType (DevicePath) == MSG_MAC_ADDR_DP)) {\r | |
304 | ReturnVal = TRUE;\r | |
305 | \r | |
306 | if (DEVICE_MANAGER_FORM_ID == NextShowFormId) {\r | |
307 | *NeedAddItem = TRUE;\r | |
308 | break;\r | |
d1102dba LG |
309 | }\r |
310 | \r | |
32465d9a DB |
311 | if (!GetMacAddressString((MAC_ADDR_DEVICE_PATH*)DevicePath, &Buffer)) {\r |
312 | break;\r | |
313 | }\r | |
314 | \r | |
315 | if (NETWORK_DEVICE_FORM_ID == NextShowFormId) {\r | |
316 | if (StrCmp (Buffer, mSelectedMacAddrString) == 0) {\r | |
317 | *NeedAddItem = TRUE;\r | |
318 | }\r | |
319 | break;\r | |
320 | }\r | |
321 | \r | |
322 | if (NETWORK_DEVICE_LIST_FORM_ID == NextShowFormId) {\r | |
323 | //\r | |
d1102dba | 324 | // Same handle may has two network child handle, so the questionid\r |
32465d9a DB |
325 | // has the offset of SAME_HANDLE_KEY_OFFSET.\r |
326 | //\r | |
327 | if (AddIdToMacDeviceList (Buffer)) {\r | |
328 | *NeedAddItem = TRUE;\r | |
329 | }\r | |
330 | break;\r | |
331 | }\r | |
332 | }\r | |
333 | DevicePath = NextDevicePathNode (DevicePath);\r | |
334 | }\r | |
335 | \r | |
336 | if (Buffer != NULL) {\r | |
337 | FreePool (Buffer);\r | |
338 | }\r | |
339 | \r | |
340 | return ReturnVal;\r | |
341 | }\r | |
342 | \r | |
343 | /**\r | |
344 | Check to see if the device path is for the network device.\r | |
345 | \r | |
346 | @param Handle The HII handle which include the mac address device path.\r | |
347 | @param NextShowFormId The FormId of the form which will be show next time.\r | |
348 | @param ItemCount The new add Mac address item count.\r | |
349 | \r | |
350 | @retval TRUE Need to add new item in the menu.\r | |
351 | @return FALSE Do not need to add the menu about the network.\r | |
352 | \r | |
353 | **/\r | |
d1102dba | 354 | BOOLEAN\r |
32465d9a DB |
355 | IsNeedAddNetworkMenu (\r |
356 | IN EFI_HII_HANDLE Handle,\r | |
357 | IN EFI_FORM_ID NextShowFormId,\r | |
358 | OUT UINTN *ItemCount\r | |
359 | )\r | |
360 | {\r | |
361 | EFI_STATUS Status;\r | |
362 | UINTN EntryCount;\r | |
d1102dba | 363 | UINTN Index;\r |
32465d9a DB |
364 | EFI_HANDLE DriverHandle;\r |
365 | EFI_HANDLE ControllerHandle;\r | |
366 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
367 | EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;\r | |
368 | EFI_DEVICE_PATH_PROTOCOL *ChildDevicePath;\r | |
369 | EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r | |
370 | BOOLEAN IsNeedAdd;\r | |
371 | \r | |
32465d9a DB |
372 | IsNeedAdd = FALSE;\r |
373 | OpenInfoBuffer = NULL;\r | |
374 | if ((Handle == NULL) || (ItemCount == NULL)) {\r | |
375 | return FALSE;\r | |
376 | }\r | |
377 | *ItemCount = 0;\r | |
378 | \r | |
379 | Status = gHiiDatabase->GetPackageListHandle (gHiiDatabase, Handle, &DriverHandle);\r | |
380 | if (EFI_ERROR (Status)) {\r | |
381 | return FALSE;\r | |
382 | }\r | |
383 | //\r | |
384 | // Get the device path by the got Driver handle .\r | |
385 | //\r | |
386 | Status = gBS->HandleProtocol (DriverHandle, &gEfiDevicePathProtocolGuid, (VOID **) &DevicePath);\r | |
387 | if (EFI_ERROR (Status)) {\r | |
388 | return FALSE;\r | |
389 | }\r | |
390 | TmpDevicePath = DevicePath;\r | |
391 | \r | |
d1102dba | 392 | //\r |
32465d9a | 393 | // Check whether this device path include mac address device path.\r |
d1102dba | 394 | // If this path has mac address path, get the value whether need\r |
32465d9a DB |
395 | // add this info to the menu and return.\r |
396 | // Else check more about the child handle devcie path.\r | |
397 | //\r | |
398 | if (IsMacAddressDevicePath(TmpDevicePath, NextShowFormId,&IsNeedAdd)) {\r | |
399 | if ((NETWORK_DEVICE_LIST_FORM_ID == NextShowFormId) && IsNeedAdd) {\r | |
400 | (*ItemCount) = 1;\r | |
401 | }\r | |
402 | return IsNeedAdd;\r | |
403 | }\r | |
404 | \r | |
405 | //\r | |
406 | // Search whether this path is the controller path, not he child handle path.\r | |
407 | // And the child handle has the network devcie connected.\r | |
408 | //\r | |
409 | TmpDevicePath = DevicePath;\r | |
410 | Status = gBS->LocateDevicePath(&gEfiDevicePathProtocolGuid, &TmpDevicePath, &ControllerHandle);\r | |
411 | if (EFI_ERROR (Status)) {\r | |
412 | return FALSE;\r | |
413 | }\r | |
414 | \r | |
415 | if (!IsDevicePathEnd (TmpDevicePath)) {\r | |
d1102dba | 416 | return FALSE;\r |
32465d9a DB |
417 | }\r |
418 | \r | |
419 | //\r | |
420 | // Retrieve the list of agents that are consuming the specific protocol\r | |
421 | // on ControllerHandle.\r | |
422 | // The buffer point by OpenInfoBuffer need be free at this function.\r | |
423 | //\r | |
424 | Status = gBS->OpenProtocolInformation (\r | |
425 | ControllerHandle,\r | |
426 | &gEfiPciIoProtocolGuid,\r | |
427 | &OpenInfoBuffer,\r | |
428 | &EntryCount\r | |
429 | );\r | |
430 | if (EFI_ERROR (Status)) {\r | |
431 | return FALSE;\r | |
432 | }\r | |
433 | \r | |
434 | //\r | |
435 | // Inspect if ChildHandle is one of the agents.\r | |
436 | //\r | |
437 | Status = EFI_UNSUPPORTED;\r | |
438 | for (Index = 0; Index < EntryCount; Index++) {\r | |
439 | //\r | |
440 | // Query all the children created by the controller handle's driver\r | |
441 | //\r | |
442 | if ((OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r | |
443 | Status = gBS->OpenProtocol (\r | |
444 | OpenInfoBuffer[Index].ControllerHandle,\r | |
445 | &gEfiDevicePathProtocolGuid,\r | |
446 | (VOID **) &ChildDevicePath,\r | |
447 | NULL,\r | |
448 | NULL,\r | |
449 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
450 | );\r | |
451 | if (EFI_ERROR (Status)) {\r | |
452 | continue;\r | |
453 | }\r | |
454 | \r | |
d1102dba | 455 | //\r |
32465d9a DB |
456 | // Check whether this device path include mac address device path.\r |
457 | //\r | |
458 | if (!IsMacAddressDevicePath(ChildDevicePath, NextShowFormId,&IsNeedAdd)) {\r | |
459 | //\r | |
460 | // If this path not has mac address path, check the other.\r | |
461 | //\r | |
462 | continue;\r | |
463 | } else {\r | |
464 | //\r | |
465 | // If need to update the NETWORK_DEVICE_LIST_FORM, try to get more.\r | |
466 | //\r | |
467 | if ((NETWORK_DEVICE_LIST_FORM_ID == NextShowFormId)) {\r | |
468 | if (IsNeedAdd) {\r | |
469 | (*ItemCount) += 1;\r | |
470 | }\r | |
471 | continue;\r | |
472 | } else {\r | |
473 | //\r | |
474 | // If need to update other form, return whether need to add to the menu.\r | |
d1102dba | 475 | //\r |
32465d9a DB |
476 | goto Done;\r |
477 | }\r | |
478 | }\r | |
479 | }\r | |
480 | }\r | |
481 | \r | |
482 | Done:\r | |
483 | if (OpenInfoBuffer != NULL) {\r | |
d1102dba | 484 | FreePool (OpenInfoBuffer);\r |
32465d9a | 485 | }\r |
d1102dba | 486 | return IsNeedAdd;\r |
32465d9a DB |
487 | }\r |
488 | \r | |
489 | /**\r | |
490 | Dynamic create Hii information for Device Manager.\r | |
491 | \r | |
492 | @param NextShowFormId The FormId which need to be show.\r | |
493 | \r | |
494 | **/\r | |
495 | VOID\r | |
496 | CreateDeviceManagerForm(\r | |
497 | IN EFI_FORM_ID NextShowFormId\r | |
498 | )\r | |
499 | {\r | |
500 | UINTN Index;\r | |
501 | EFI_STRING String;\r | |
502 | EFI_STRING_ID Token;\r | |
503 | EFI_STRING_ID TokenHelp;\r | |
504 | EFI_HII_HANDLE *HiiHandles;\r | |
505 | EFI_HII_HANDLE HiiHandle;\r | |
506 | EFI_GUID FormSetGuid;\r | |
507 | VOID *StartOpCodeHandle;\r | |
508 | VOID *EndOpCodeHandle;\r | |
509 | EFI_IFR_GUID_LABEL *StartLabel;\r | |
510 | EFI_IFR_GUID_LABEL *EndLabel;\r | |
511 | BOOLEAN AddNetworkMenu;\r | |
512 | UINTN AddItemCount;\r | |
513 | UINTN NewStringLen;\r | |
514 | EFI_STRING NewStringTitle;\r | |
515 | CHAR16 *DevicePathStr;\r | |
516 | EFI_STRING_ID DevicePathId;\r | |
d1102dba LG |
517 | EFI_IFR_FORM_SET *Buffer;\r |
518 | UINTN BufferSize;\r | |
519 | UINT8 ClassGuidNum;\r | |
520 | EFI_GUID *ClassGuid;\r | |
32465d9a DB |
521 | UINTN TempSize;\r |
522 | UINT8 *Ptr;\r | |
523 | EFI_STATUS Status;\r | |
524 | \r | |
525 | TempSize =0;\r | |
526 | BufferSize = 0;\r | |
527 | Buffer = NULL;\r | |
528 | \r | |
529 | HiiHandle = gDeviceManagerPrivate.HiiHandle;\r | |
530 | AddNetworkMenu = FALSE;\r | |
531 | AddItemCount = 0;\r | |
532 | //\r | |
533 | // If need show the Network device list form, clear the old save list first.\r | |
534 | //\r | |
535 | if ((NextShowFormId == NETWORK_DEVICE_LIST_FORM_ID) && (mMacDeviceList.CurListLen > 0)) {\r | |
536 | mMacDeviceList.CurListLen = 0;\r | |
537 | }\r | |
538 | \r | |
539 | //\r | |
540 | // Update the network device form titile.\r | |
541 | //\r | |
542 | if (NextShowFormId == NETWORK_DEVICE_FORM_ID) {\r | |
205a4b0c JW |
543 | String = HiiGetString (HiiHandle, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE_HEAD), NULL);\r |
544 | if (String == NULL) {\r | |
545 | return;\r | |
546 | }\r | |
547 | NewStringLen = StrLen (mSelectedMacAddrString) * 2;\r | |
548 | NewStringLen += (StrLen (String) + 2) * 2;\r | |
32465d9a DB |
549 | NewStringTitle = AllocatePool (NewStringLen);\r |
550 | UnicodeSPrint (NewStringTitle, NewStringLen, L"%s %s", String, mSelectedMacAddrString);\r | |
205a4b0c | 551 | HiiSetString (HiiHandle, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE), NewStringTitle, NULL);\r |
32465d9a DB |
552 | FreePool (String);\r |
553 | FreePool (NewStringTitle);\r | |
554 | }\r | |
555 | \r | |
556 | //\r | |
557 | // Allocate space for creation of UpdateData Buffer\r | |
558 | //\r | |
559 | StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
560 | ASSERT (StartOpCodeHandle != NULL);\r | |
561 | \r | |
562 | EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
563 | ASSERT (EndOpCodeHandle != NULL);\r | |
564 | \r | |
565 | //\r | |
566 | // Create Hii Extend Label OpCode as the start opcode\r | |
567 | //\r | |
568 | StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r | |
569 | StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
570 | //\r | |
571 | // According to the next show Form id(mNextShowFormId) to decide which form need to update.\r | |
572 | //\r | |
573 | StartLabel->Number = (UINT16) (LABEL_FORM_ID_OFFSET + NextShowFormId);\r | |
574 | \r | |
575 | //\r | |
576 | // Create Hii Extend Label OpCode as the end opcode\r | |
577 | //\r | |
578 | EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r | |
579 | EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
580 | EndLabel->Number = LABEL_END;\r | |
581 | \r | |
582 | //\r | |
583 | // Get all the Hii handles\r | |
584 | //\r | |
585 | HiiHandles = HiiGetHiiHandles (NULL);\r | |
586 | ASSERT (HiiHandles != NULL);\r | |
587 | \r | |
588 | //\r | |
589 | // Search for formset of each class type\r | |
590 | //\r | |
591 | for (Index = 0; HiiHandles[Index] != NULL; Index++) {\r | |
592 | Status = HiiGetFormSetFromHiiHandle(HiiHandles[Index], &Buffer,&BufferSize);\r | |
593 | if (EFI_ERROR (Status)){\r | |
594 | continue;\r | |
595 | }\r | |
596 | Ptr = (UINT8 *)Buffer;\r | |
597 | while(TempSize < BufferSize) {\r | |
598 | TempSize += ((EFI_IFR_OP_HEADER *) Ptr)->Length;\r | |
599 | if (((EFI_IFR_OP_HEADER *) Ptr)->Length <= OFFSET_OF (EFI_IFR_FORM_SET, Flags)){\r | |
600 | Ptr += ((EFI_IFR_OP_HEADER *) Ptr)->Length;\r | |
601 | continue;\r | |
d1102dba | 602 | }\r |
32465d9a DB |
603 | \r |
604 | ClassGuidNum = (UINT8) (((EFI_IFR_FORM_SET *)Ptr)->Flags & 0x3);\r | |
605 | ClassGuid = (EFI_GUID *) (VOID *)(Ptr + sizeof (EFI_IFR_FORM_SET));\r | |
606 | while (ClassGuidNum-- > 0) {\r | |
607 | if (CompareGuid (&gEfiHiiPlatformSetupFormsetGuid, ClassGuid)== 0) {\r | |
608 | ClassGuid ++;\r | |
609 | continue;\r | |
610 | }\r | |
611 | \r | |
612 | String = HiiGetString (HiiHandles[Index], ((EFI_IFR_FORM_SET *)Ptr)->FormSetTitle, NULL);\r | |
613 | if (String == NULL) {\r | |
614 | String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);\r | |
615 | ASSERT (String != NULL);\r | |
616 | }\r | |
617 | Token = HiiSetString (HiiHandle, 0, String, NULL);\r | |
618 | FreePool (String);\r | |
619 | \r | |
620 | String = HiiGetString (HiiHandles[Index], ((EFI_IFR_FORM_SET *)Ptr)->Help, NULL);\r | |
621 | if (String == NULL) {\r | |
622 | String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);\r | |
623 | ASSERT (String != NULL);\r | |
624 | }\r | |
625 | TokenHelp = HiiSetString (HiiHandle, 0, String, NULL);\r | |
626 | FreePool (String);\r | |
627 | \r | |
628 | FormSetGuid = ((EFI_IFR_FORM_SET *)Ptr)->Guid;\r | |
629 | \r | |
630 | //\r | |
631 | // Network device process\r | |
d1102dba | 632 | //\r |
32465d9a DB |
633 | if (IsNeedAddNetworkMenu (HiiHandles[Index], NextShowFormId,&AddItemCount)) {\r |
634 | if (NextShowFormId == DEVICE_MANAGER_FORM_ID) {\r | |
635 | //\r | |
636 | // Only show one menu item "Network Config" in the device manger form.\r | |
637 | //\r | |
638 | if (!AddNetworkMenu) {\r | |
639 | AddNetworkMenu = TRUE;\r | |
640 | HiiCreateGotoOpCode (\r | |
641 | StartOpCodeHandle,\r | |
642 | NETWORK_DEVICE_LIST_FORM_ID,\r | |
643 | STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_TITLE),\r | |
644 | STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_HELP),\r | |
645 | EFI_IFR_FLAG_CALLBACK,\r | |
646 | (EFI_QUESTION_ID) QUESTION_NETWORK_DEVICE_ID\r | |
647 | );\r | |
648 | }\r | |
649 | } else if (NextShowFormId == NETWORK_DEVICE_LIST_FORM_ID) {\r | |
650 | //\r | |
651 | // In network device list form, same mac address device only show one menu.\r | |
652 | //\r | |
653 | while (AddItemCount > 0) {\r | |
654 | HiiCreateGotoOpCode (\r | |
655 | StartOpCodeHandle,\r | |
656 | NETWORK_DEVICE_FORM_ID,\r | |
657 | mMacDeviceList.NodeList[mMacDeviceList.CurListLen - AddItemCount].PromptId,\r | |
658 | STRING_TOKEN (STR_NETWORK_DEVICE_HELP),\r | |
659 | EFI_IFR_FLAG_CALLBACK,\r | |
660 | mMacDeviceList.NodeList[mMacDeviceList.CurListLen - AddItemCount].QuestionId\r | |
661 | );\r | |
662 | AddItemCount -= 1;\r | |
663 | }\r | |
664 | } else if (NextShowFormId == NETWORK_DEVICE_FORM_ID) {\r | |
665 | //\r | |
666 | // In network device form, only the selected mac address device need to be show.\r | |
667 | //\r | |
668 | DevicePathStr = DmExtractDevicePathFromHiiHandle(HiiHandles[Index]);\r | |
669 | DevicePathId = 0;\r | |
670 | if (DevicePathStr != NULL){\r | |
671 | DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL);\r | |
672 | FreePool(DevicePathStr);\r | |
673 | }\r | |
674 | HiiCreateGotoExOpCode (\r | |
675 | StartOpCodeHandle,\r | |
676 | 0,\r | |
677 | Token,\r | |
678 | TokenHelp,\r | |
679 | 0,\r | |
680 | (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET),\r | |
681 | 0,\r | |
d1102dba | 682 | &FormSetGuid,\r |
32465d9a DB |
683 | DevicePathId\r |
684 | );\r | |
685 | }\r | |
686 | } else {\r | |
687 | //\r | |
688 | // Not network device process, only need to show at device manger form.\r | |
689 | //\r | |
690 | if (NextShowFormId == DEVICE_MANAGER_FORM_ID) {\r | |
691 | DevicePathStr = DmExtractDevicePathFromHiiHandle(HiiHandles[Index]);\r | |
692 | DevicePathId = 0;\r | |
693 | if (DevicePathStr != NULL){\r | |
694 | DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL);\r | |
695 | FreePool(DevicePathStr);\r | |
696 | }\r | |
697 | HiiCreateGotoExOpCode (\r | |
698 | StartOpCodeHandle,\r | |
699 | 0,\r | |
700 | Token,\r | |
701 | TokenHelp,\r | |
702 | 0,\r | |
703 | (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET),\r | |
704 | 0,\r | |
705 | &FormSetGuid,\r | |
706 | DevicePathId\r | |
707 | );\r | |
708 | }\r | |
709 | }\r | |
710 | break;\r | |
711 | }\r | |
712 | \r | |
713 | Ptr += ((EFI_IFR_OP_HEADER *) Ptr)->Length;\r | |
714 | }\r | |
715 | FreePool(Buffer);\r | |
716 | Buffer = NULL;\r | |
717 | TempSize = 0;\r | |
718 | BufferSize = 0;\r | |
719 | }\r | |
720 | \r | |
721 | HiiUpdateForm (\r | |
722 | HiiHandle,\r | |
723 | &mDeviceManagerGuid,\r | |
724 | NextShowFormId,\r | |
725 | StartOpCodeHandle,\r | |
726 | EndOpCodeHandle\r | |
727 | );\r | |
728 | \r | |
729 | HiiFreeOpCodeHandle (StartOpCodeHandle);\r | |
730 | HiiFreeOpCodeHandle (EndOpCodeHandle);\r | |
731 | FreePool (HiiHandles);\r | |
732 | }\r | |
733 | \r | |
734 | /**\r | |
735 | This function allows a caller to extract the current configuration for one\r | |
736 | or more named elements from the target driver.\r | |
737 | \r | |
738 | \r | |
739 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
740 | @param Request A null-terminated Unicode string in <ConfigRequest> format.\r | |
741 | @param Progress On return, points to a character in the Request string.\r | |
742 | Points to the string's null terminator if request was successful.\r | |
743 | Points to the most recent '&' before the first failing name/value\r | |
744 | pair (or the beginning of the string if the failure is in the\r | |
745 | first name/value pair) if the request was not successful.\r | |
746 | @param Results A null-terminated Unicode string in <ConfigAltResp> format which\r | |
747 | has all values filled in for the names in the Request string.\r | |
748 | String to be allocated by the called function.\r | |
749 | \r | |
750 | @retval EFI_SUCCESS The Results is filled with the requested values.\r | |
751 | @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r | |
752 | @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r | |
753 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r | |
754 | \r | |
755 | **/\r | |
756 | EFI_STATUS\r | |
757 | EFIAPI\r | |
758 | DeviceManagerExtractConfig (\r | |
759 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
760 | IN CONST EFI_STRING Request,\r | |
761 | OUT EFI_STRING *Progress,\r | |
762 | OUT EFI_STRING *Results\r | |
763 | )\r | |
764 | {\r | |
765 | if (Progress == NULL || Results == NULL) {\r | |
766 | return EFI_INVALID_PARAMETER;\r | |
767 | }\r | |
768 | *Progress = Request;\r | |
769 | return EFI_NOT_FOUND;\r | |
770 | }\r | |
771 | \r | |
772 | /**\r | |
773 | This function processes the results of changes in configuration.\r | |
774 | \r | |
775 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
776 | @param Configuration A null-terminated Unicode string in <ConfigResp> format.\r | |
777 | @param Progress A pointer to a string filled in with the offset of the most\r | |
778 | recent '&' before the first failing name/value pair (or the\r | |
779 | beginning of the string if the failure is in the first\r | |
780 | name/value pair) or the terminating NULL if all was successful.\r | |
781 | \r | |
782 | @retval EFI_SUCCESS The Results is processed successfully.\r | |
783 | @retval EFI_INVALID_PARAMETER Configuration is NULL.\r | |
784 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r | |
785 | \r | |
786 | **/\r | |
787 | EFI_STATUS\r | |
788 | EFIAPI\r | |
789 | DeviceManagerRouteConfig (\r | |
790 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
791 | IN CONST EFI_STRING Configuration,\r | |
792 | OUT EFI_STRING *Progress\r | |
793 | )\r | |
794 | {\r | |
795 | if (Configuration == NULL || Progress == NULL) {\r | |
796 | return EFI_INVALID_PARAMETER;\r | |
797 | }\r | |
798 | \r | |
799 | *Progress = Configuration;\r | |
800 | \r | |
801 | return EFI_NOT_FOUND;\r | |
802 | }\r | |
803 | \r | |
804 | /**\r | |
805 | This function is invoked if user selected a interactive opcode from Device Manager's\r | |
806 | Formset. If user set VBIOS, the new value is saved to EFI variable.\r | |
807 | \r | |
808 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
809 | @param Action Specifies the type of action taken by the browser.\r | |
810 | @param QuestionId A unique value which is sent to the original exporting driver\r | |
811 | so that it can identify the type of data to expect.\r | |
812 | @param Type The type of value for the question.\r | |
813 | @param Value A pointer to the data being sent to the original exporting driver.\r | |
814 | @param ActionRequest On return, points to the action requested by the callback function.\r | |
815 | \r | |
816 | @retval EFI_SUCCESS The callback successfully handled the action.\r | |
817 | @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.\r | |
818 | \r | |
819 | **/\r | |
820 | EFI_STATUS\r | |
821 | EFIAPI\r | |
822 | DeviceManagerCallback (\r | |
823 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
824 | IN EFI_BROWSER_ACTION Action,\r | |
825 | IN EFI_QUESTION_ID QuestionId,\r | |
826 | IN UINT8 Type,\r | |
827 | IN EFI_IFR_TYPE_VALUE *Value,\r | |
828 | OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r | |
829 | )\r | |
830 | {\r | |
831 | UINTN CurIndex;\r | |
832 | \r | |
833 | if (Action != EFI_BROWSER_ACTION_CHANGING) {\r | |
834 | //\r | |
835 | // Do nothing for other UEFI Action. Only do call back when data is changed.\r | |
836 | //\r | |
837 | return EFI_UNSUPPORTED;\r | |
838 | }\r | |
839 | if ((Value == NULL) || (ActionRequest == NULL)) {\r | |
840 | return EFI_INVALID_PARAMETER;\r | |
841 | }\r | |
842 | if ((QuestionId < MAX_KEY_SECTION_LEN + NETWORK_DEVICE_LIST_KEY_OFFSET) && (QuestionId >= NETWORK_DEVICE_LIST_KEY_OFFSET)) {\r | |
843 | //\r | |
844 | // If user select the mac address, need to record mac address string to support next form show.\r | |
845 | //\r | |
846 | for (CurIndex = 0; CurIndex < mMacDeviceList.CurListLen; CurIndex ++) {\r | |
847 | if (mMacDeviceList.NodeList[CurIndex].QuestionId == QuestionId) {\r | |
848 | mSelectedMacAddrString = HiiGetString (gDeviceManagerPrivate.HiiHandle, mMacDeviceList.NodeList[CurIndex].PromptId, NULL);\r | |
849 | }\r | |
850 | }\r | |
851 | CreateDeviceManagerForm(NETWORK_DEVICE_FORM_ID);\r | |
852 | } else if(QuestionId == QUESTION_NETWORK_DEVICE_ID){\r | |
853 | CreateDeviceManagerForm(NETWORK_DEVICE_LIST_FORM_ID);\r | |
854 | }\r | |
855 | \r | |
856 | return EFI_SUCCESS;\r | |
857 | }\r | |
858 | \r | |
859 | /**\r | |
860 | Install Boot Manager Menu driver.\r | |
861 | \r | |
862 | @param ImageHandle The image handle.\r | |
863 | @param SystemTable The system table.\r | |
864 | \r | |
865 | @retval EFI_SUCEESS Install Boot manager menu success.\r | |
866 | @retval Other Return error status.\r | |
867 | \r | |
868 | **/\r | |
869 | EFI_STATUS\r | |
870 | EFIAPI\r | |
3910f669 | 871 | DeviceManagerUiLibConstructor (\r |
32465d9a DB |
872 | IN EFI_HANDLE ImageHandle,\r |
873 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
874 | )\r | |
875 | {\r | |
876 | EFI_STATUS Status;\r | |
877 | \r | |
878 | gDeviceManagerPrivate.DriverHandle = NULL;\r | |
879 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
880 | &gDeviceManagerPrivate.DriverHandle,\r | |
881 | &gEfiDevicePathProtocolGuid,\r | |
882 | &mDeviceManagerHiiVendorDevicePath,\r | |
883 | &gEfiHiiConfigAccessProtocolGuid,\r | |
884 | &gDeviceManagerPrivate.ConfigAccess,\r | |
885 | NULL\r | |
886 | );\r | |
887 | ASSERT_EFI_ERROR (Status);\r | |
888 | \r | |
889 | //\r | |
890 | // Publish our HII data.\r | |
891 | //\r | |
892 | gDeviceManagerPrivate.HiiHandle = HiiAddPackages (\r | |
893 | &mDeviceManagerGuid,\r | |
894 | gDeviceManagerPrivate.DriverHandle,\r | |
895 | DeviceManagerVfrBin,\r | |
3910f669 | 896 | DeviceManagerUiLibStrings,\r |
32465d9a DB |
897 | NULL\r |
898 | );\r | |
899 | ASSERT (gDeviceManagerPrivate.HiiHandle != NULL);\r | |
900 | \r | |
901 | //\r | |
d1102dba | 902 | // Update boot manager page\r |
32465d9a DB |
903 | //\r |
904 | CreateDeviceManagerForm (DEVICE_MANAGER_FORM_ID);\r | |
905 | \r | |
906 | return EFI_SUCCESS;\r | |
907 | }\r | |
908 | \r | |
909 | /**\r | |
910 | Unloads the application and its installed protocol.\r | |
911 | \r | |
912 | @param ImageHandle Handle that identifies the image to be unloaded.\r | |
913 | @param SystemTable The system table.\r | |
914 | \r | |
915 | @retval EFI_SUCCESS The image has been unloaded.\r | |
916 | **/\r | |
917 | EFI_STATUS\r | |
918 | EFIAPI\r | |
3910f669 | 919 | DeviceManagerUiLibDestructor(\r |
32465d9a DB |
920 | IN EFI_HANDLE ImageHandle,\r |
921 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
922 | )\r | |
923 | {\r | |
924 | EFI_STATUS Status;\r | |
925 | \r | |
926 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
927 | gDeviceManagerPrivate.DriverHandle,\r | |
928 | &gEfiDevicePathProtocolGuid,\r | |
929 | &mDeviceManagerHiiVendorDevicePath,\r | |
930 | &gEfiHiiConfigAccessProtocolGuid,\r | |
931 | &gDeviceManagerPrivate.ConfigAccess,\r | |
932 | NULL\r | |
933 | );\r | |
934 | ASSERT_EFI_ERROR (Status);\r | |
935 | \r | |
936 | HiiRemovePackages (gDeviceManagerPrivate.HiiHandle);\r | |
937 | \r | |
938 | return EFI_SUCCESS;\r | |
939 | }\r | |
940 | \r |