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