]>
Commit | Line | Data |
---|---|---|
143f0b1d ED |
1 | /** @file\r |
2 | The platform device manager reference implementation\r | |
3 | \r | |
afc244a5 | 4 | Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>\r |
143f0b1d ED |
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 | FakeExtractConfig,\r | |
23 | FakeRouteConfig,\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 | DEVICE_MANAGER_MENU_ITEM mDeviceManagerMenuItemTable[] = {\r | |
44 | { STRING_TOKEN (STR_DISK_DEVICE), EFI_DISK_DEVICE_CLASS },\r | |
45 | { STRING_TOKEN (STR_VIDEO_DEVICE), EFI_VIDEO_DEVICE_CLASS },\r | |
46 | { STRING_TOKEN (STR_NETWORK_DEVICE), EFI_NETWORK_DEVICE_CLASS },\r | |
47 | { STRING_TOKEN (STR_INPUT_DEVICE), EFI_INPUT_DEVICE_CLASS },\r | |
48 | { STRING_TOKEN (STR_ON_BOARD_DEVICE), EFI_ON_BOARD_DEVICE_CLASS },\r | |
49 | { STRING_TOKEN (STR_OTHER_DEVICE), EFI_OTHER_DEVICE_CLASS }\r | |
50 | };\r | |
51 | \r | |
52 | HII_VENDOR_DEVICE_PATH mDeviceManagerHiiVendorDevicePath = {\r | |
53 | {\r | |
54 | {\r | |
55 | HARDWARE_DEVICE_PATH,\r | |
56 | HW_VENDOR_DP,\r | |
57 | {\r | |
58 | (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r | |
59 | (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r | |
60 | }\r | |
61 | },\r | |
62 | //\r | |
63 | // {102579A0-3686-466e-ACD8-80C087044F4A}\r | |
64 | //\r | |
65 | { 0x102579a0, 0x3686, 0x466e, { 0xac, 0xd8, 0x80, 0xc0, 0x87, 0x4, 0x4f, 0x4a } }\r | |
66 | },\r | |
67 | {\r | |
68 | END_DEVICE_PATH_TYPE,\r | |
69 | END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
70 | { \r | |
71 | (UINT8) (END_DEVICE_PATH_LENGTH),\r | |
72 | (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r | |
73 | }\r | |
74 | }\r | |
75 | };\r | |
76 | \r | |
77 | /**\r | |
78 | This function is invoked if user selected a interactive opcode from Device Manager's\r | |
79 | Formset. If user set VBIOS, the new value is saved to EFI variable.\r | |
80 | \r | |
81 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
82 | @param Action Specifies the type of action taken by the browser.\r | |
83 | @param QuestionId A unique value which is sent to the original exporting driver\r | |
84 | so that it can identify the type of data to expect.\r | |
85 | @param Type The type of value for the question.\r | |
86 | @param Value A pointer to the data being sent to the original exporting driver.\r | |
87 | @param ActionRequest On return, points to the action requested by the callback function.\r | |
88 | \r | |
89 | @retval EFI_SUCCESS The callback successfully handled the action.\r | |
90 | @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.\r | |
91 | \r | |
92 | **/\r | |
93 | EFI_STATUS\r | |
94 | EFIAPI\r | |
95 | DeviceManagerCallback (\r | |
96 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
97 | IN EFI_BROWSER_ACTION Action,\r | |
98 | IN EFI_QUESTION_ID QuestionId,\r | |
99 | IN UINT8 Type,\r | |
100 | IN EFI_IFR_TYPE_VALUE *Value,\r | |
101 | OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r | |
102 | )\r | |
103 | {\r | |
104 | UINTN CurIndex;\r | |
105 | \r | |
106 | if (Action != EFI_BROWSER_ACTION_CHANGING) {\r | |
107 | //\r | |
108 | // Do nothing for other UEFI Action. Only do call back when data is changed.\r | |
109 | //\r | |
110 | return EFI_UNSUPPORTED;\r | |
111 | }\r | |
112 | \r | |
113 | if ((Value == NULL) || (ActionRequest == NULL)) {\r | |
114 | return EFI_INVALID_PARAMETER;\r | |
115 | }\r | |
116 | if ((QuestionId < MAX_KEY_SECTION_LEN + NETWORK_DEVICE_LIST_KEY_OFFSET) && (QuestionId >= NETWORK_DEVICE_LIST_KEY_OFFSET)) {\r | |
117 | //\r | |
118 | // If user select the mac address, need to record mac address string to support next form show.\r | |
119 | //\r | |
120 | for (CurIndex = 0; CurIndex < mMacDeviceList.CurListLen; CurIndex ++) {\r | |
121 | if (mMacDeviceList.NodeList[CurIndex].QuestionId == QuestionId) {\r | |
122 | mSelectedMacAddrString = HiiGetString (gDeviceManagerPrivate.HiiHandle, mMacDeviceList.NodeList[CurIndex].PromptId, NULL);\r | |
123 | }\r | |
124 | }\r | |
125 | CreateDeviceManagerForm(NETWORK_DEVICE_FORM_ID);\r | |
126 | } else if(QuestionId == QUESTION_NETWORK_DEVICE_ID){\r | |
127 | CreateDeviceManagerForm(NETWORK_DEVICE_LIST_FORM_ID);\r | |
128 | }\r | |
129 | \r | |
130 | return EFI_SUCCESS;\r | |
131 | }\r | |
132 | \r | |
133 | /**\r | |
134 | Get the mac address string from the device path.\r | |
135 | if the device path has the vlan, get the vanid also.\r | |
136 | \r | |
137 | @param MacAddressNode Device path begin with mac address \r | |
138 | @param PBuffer Output string buffer contain mac address.\r | |
139 | \r | |
140 | **/\r | |
141 | BOOLEAN \r | |
142 | GetMacAddressString(\r | |
143 | IN MAC_ADDR_DEVICE_PATH *MacAddressNode,\r | |
144 | OUT CHAR16 **PBuffer\r | |
145 | )\r | |
146 | {\r | |
147 | UINTN HwAddressSize;\r | |
148 | UINTN Index;\r | |
149 | UINT8 *HwAddress;\r | |
150 | EFI_DEVICE_PATH_PROTOCOL *Node;\r | |
151 | UINT16 VlanId;\r | |
152 | CHAR16 *String;\r | |
153 | UINTN BufferLen;\r | |
154 | \r | |
155 | VlanId = 0;\r | |
156 | String = NULL;\r | |
157 | ASSERT(MacAddressNode != NULL);\r | |
158 | \r | |
159 | HwAddressSize = sizeof (EFI_MAC_ADDRESS);\r | |
160 | if (MacAddressNode->IfType == 0x01 || MacAddressNode->IfType == 0x00) {\r | |
161 | HwAddressSize = 6;\r | |
162 | }\r | |
163 | \r | |
164 | //\r | |
165 | // The output format is MAC:XX:XX:XX:...\XXXX\r | |
166 | // The size is the Number size + ":" size + Vlan size(\XXXX) + End\r | |
167 | //\r | |
168 | BufferLen = (4 + 2 * HwAddressSize + (HwAddressSize - 1) + 5 + 1) * sizeof (CHAR16);\r | |
169 | String = AllocateZeroPool (BufferLen);\r | |
170 | if (String == NULL) {\r | |
171 | return FALSE;\r | |
172 | }\r | |
173 | \r | |
174 | *PBuffer = String;\r | |
d91cb870 | 175 | StrCpyS(String, BufferLen / sizeof (CHAR16), L"MAC:");\r |
143f0b1d ED |
176 | String += 4;\r |
177 | \r | |
178 | //\r | |
179 | // Convert the MAC address into a unicode string.\r | |
180 | //\r | |
181 | HwAddress = &MacAddressNode->MacAddress.Addr[0];\r | |
182 | for (Index = 0; Index < HwAddressSize; Index++) {\r | |
183 | String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, *(HwAddress++), 2);\r | |
184 | if (Index < HwAddressSize - 1) {\r | |
185 | *String++ = L':';\r | |
186 | }\r | |
187 | }\r | |
188 | \r | |
189 | //\r | |
190 | // If VLAN is configured, it will need extra 5 characters like "\0005".\r | |
191 | // Plus one unicode character for the null-terminator.\r | |
192 | //\r | |
193 | Node = (EFI_DEVICE_PATH_PROTOCOL *)MacAddressNode;\r | |
194 | while (!IsDevicePathEnd (Node)) {\r | |
195 | if (Node->Type == MESSAGING_DEVICE_PATH && Node->SubType == MSG_VLAN_DP) {\r | |
196 | VlanId = ((VLAN_DEVICE_PATH *) Node)->VlanId;\r | |
197 | }\r | |
198 | Node = NextDevicePathNode (Node);\r | |
199 | }\r | |
200 | \r | |
201 | if (VlanId != 0) {\r | |
202 | *String++ = L'\\';\r | |
203 | String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, VlanId, 4);\r | |
204 | }\r | |
205 | \r | |
206 | //\r | |
207 | // Null terminate the Unicode string\r | |
208 | //\r | |
209 | *String = L'\0';\r | |
210 | \r | |
211 | return TRUE;\r | |
212 | }\r | |
213 | \r | |
214 | /**\r | |
215 | Save question id and prompt id to the mac device list.\r | |
216 | If the same mac address has saved yet, no need to add more.\r | |
217 | \r | |
218 | @param MacAddrString Mac address string.\r | |
219 | \r | |
220 | @retval EFI_SUCCESS Add the item is successful.\r | |
221 | @return Other values if failed to Add the item.\r | |
222 | **/\r | |
223 | BOOLEAN \r | |
224 | AddIdToMacDeviceList (\r | |
225 | IN EFI_STRING MacAddrString\r | |
226 | )\r | |
227 | {\r | |
228 | MENU_INFO_ITEM *TempDeviceList;\r | |
229 | UINTN Index;\r | |
230 | EFI_STRING StoredString;\r | |
231 | EFI_STRING_ID PromptId;\r | |
232 | EFI_HII_HANDLE HiiHandle;\r | |
233 | \r | |
234 | HiiHandle = gDeviceManagerPrivate.HiiHandle;\r | |
235 | TempDeviceList = NULL;\r | |
236 | \r | |
237 | for (Index = 0; Index < mMacDeviceList.CurListLen; Index ++) {\r | |
238 | StoredString = HiiGetString (HiiHandle, mMacDeviceList.NodeList[Index].PromptId, NULL);\r | |
239 | if (StoredString == NULL) {\r | |
240 | return FALSE;\r | |
241 | }\r | |
242 | \r | |
243 | //\r | |
244 | // Already has save the same mac address to the list.\r | |
245 | //\r | |
246 | if (StrCmp (MacAddrString, StoredString) == 0) {\r | |
247 | return FALSE;\r | |
248 | }\r | |
249 | }\r | |
250 | \r | |
251 | PromptId = HiiSetString(HiiHandle, 0, MacAddrString, NULL);\r | |
252 | //\r | |
253 | // If not in the list, save it.\r | |
254 | //\r | |
255 | if (mMacDeviceList.MaxListLen > mMacDeviceList.CurListLen + 1) {\r | |
256 | mMacDeviceList.NodeList[mMacDeviceList.CurListLen].PromptId = PromptId;\r | |
257 | mMacDeviceList.NodeList[mMacDeviceList.CurListLen].QuestionId = (EFI_QUESTION_ID) (mMacDeviceList.CurListLen + NETWORK_DEVICE_LIST_KEY_OFFSET);\r | |
258 | } else {\r | |
259 | mMacDeviceList.MaxListLen += MAX_MAC_ADDRESS_NODE_LIST_LEN;\r | |
260 | if (mMacDeviceList.CurListLen != 0) {\r | |
261 | TempDeviceList = (MENU_INFO_ITEM *)AllocateCopyPool (sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen, (VOID *)mMacDeviceList.NodeList);\r | |
262 | } else {\r | |
263 | TempDeviceList = (MENU_INFO_ITEM *)AllocatePool (sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen);\r | |
264 | }\r | |
265 | \r | |
266 | if (TempDeviceList == NULL) {\r | |
267 | return FALSE;\r | |
268 | }\r | |
269 | TempDeviceList[mMacDeviceList.CurListLen].PromptId = PromptId; \r | |
270 | TempDeviceList[mMacDeviceList.CurListLen].QuestionId = (EFI_QUESTION_ID) (mMacDeviceList.CurListLen + NETWORK_DEVICE_LIST_KEY_OFFSET);\r | |
271 | \r | |
272 | if (mMacDeviceList.CurListLen > 0) {\r | |
273 | FreePool(mMacDeviceList.NodeList);\r | |
274 | }\r | |
275 | \r | |
276 | mMacDeviceList.NodeList = TempDeviceList;\r | |
277 | }\r | |
278 | mMacDeviceList.CurListLen ++;\r | |
279 | \r | |
280 | return TRUE;\r | |
281 | }\r | |
282 | \r | |
283 | /**\r | |
284 | Check the devcie path, try to find whether it has mac address path.\r | |
285 | \r | |
286 | In this function, first need to check whether this path has mac address path.\r | |
287 | second, when the mac address device path has find, also need to deicide whether\r | |
288 | need to add this mac address relate info to the menu.\r | |
289 | \r | |
290 | @param *Node Input device which need to be check.\r | |
291 | @param NextShowFormId FormId Which need to be show.\r | |
292 | @param *NeedAddItem Whether need to add the menu in the network device list.\r | |
293 | \r | |
294 | @retval TRUE Has mac address device path.\r | |
295 | @retval FALSE NOT Has mac address device path. \r | |
296 | \r | |
297 | **/\r | |
298 | BOOLEAN\r | |
299 | IsMacAddressDevicePath (\r | |
300 | IN VOID *Node,\r | |
301 | IN EFI_FORM_ID NextShowFormId,\r | |
302 | OUT BOOLEAN *NeedAddItem\r | |
303 | )\r | |
304 | {\r | |
305 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
306 | CHAR16 *Buffer;\r | |
307 | BOOLEAN ReturnVal;\r | |
308 | \r | |
309 | ASSERT (Node != NULL);\r | |
310 | *NeedAddItem = FALSE;\r | |
311 | ReturnVal = FALSE;\r | |
312 | Buffer = NULL;\r | |
313 | \r | |
314 | DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Node;\r | |
315 | \r | |
316 | //\r | |
317 | // find the partition device path node\r | |
318 | //\r | |
319 | while (!IsDevicePathEnd (DevicePath)) {\r | |
320 | if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&\r | |
321 | (DevicePathSubType (DevicePath) == MSG_MAC_ADDR_DP)) {\r | |
322 | ReturnVal = TRUE;\r | |
323 | \r | |
324 | if (DEVICE_MANAGER_FORM_ID == NextShowFormId) {\r | |
325 | *NeedAddItem = TRUE;\r | |
326 | break;\r | |
327 | } \r | |
328 | \r | |
329 | if (!GetMacAddressString((MAC_ADDR_DEVICE_PATH*)DevicePath, &Buffer)) {\r | |
330 | break;\r | |
331 | }\r | |
332 | \r | |
333 | if (NETWORK_DEVICE_FORM_ID == NextShowFormId) {\r | |
334 | if (StrCmp (Buffer, mSelectedMacAddrString) == 0) {\r | |
335 | *NeedAddItem = TRUE;\r | |
336 | }\r | |
337 | break;\r | |
338 | }\r | |
339 | \r | |
340 | if (NETWORK_DEVICE_LIST_FORM_ID == NextShowFormId) {\r | |
341 | //\r | |
342 | // Same handle may has two network child handle, so the questionid \r | |
343 | // has the offset of SAME_HANDLE_KEY_OFFSET.\r | |
344 | //\r | |
345 | if (AddIdToMacDeviceList (Buffer)) {\r | |
346 | *NeedAddItem = TRUE;\r | |
347 | }\r | |
348 | break;\r | |
349 | }\r | |
350 | } \r | |
351 | DevicePath = NextDevicePathNode (DevicePath);\r | |
352 | }\r | |
353 | \r | |
354 | if (Buffer != NULL) {\r | |
355 | FreePool (Buffer);\r | |
356 | }\r | |
357 | \r | |
358 | return ReturnVal;\r | |
359 | }\r | |
360 | \r | |
361 | /**\r | |
362 | Check to see if the device path is for the network device.\r | |
363 | \r | |
364 | @param Handle The HII handle which include the mac address device path.\r | |
365 | @param NextShowFormId The FormId of the form which will be show next time.\r | |
366 | @param ItemCount The new add Mac address item count.\r | |
367 | \r | |
368 | @retval TRUE Need to add new item in the menu.\r | |
369 | @return FALSE Do not need to add the menu about the network.\r | |
370 | \r | |
371 | **/\r | |
372 | BOOLEAN \r | |
373 | IsNeedAddNetworkMenu (\r | |
374 | IN EFI_HII_HANDLE Handle,\r | |
375 | IN EFI_FORM_ID NextShowFormId,\r | |
376 | OUT UINTN *ItemCount\r | |
377 | )\r | |
378 | {\r | |
379 | EFI_STATUS Status;\r | |
380 | UINTN EntryCount;\r | |
381 | UINTN Index; \r | |
382 | EFI_HII_HANDLE HiiDeviceManagerHandle;\r | |
383 | EFI_HANDLE DriverHandle;\r | |
384 | EFI_HANDLE ControllerHandle;\r | |
385 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
386 | EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;\r | |
387 | EFI_DEVICE_PATH_PROTOCOL *ChildDevicePath;\r | |
388 | EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r | |
389 | BOOLEAN IsNeedAdd;\r | |
390 | \r | |
391 | HiiDeviceManagerHandle = gDeviceManagerPrivate.HiiHandle;\r | |
392 | IsNeedAdd = FALSE;\r | |
393 | OpenInfoBuffer = NULL;\r | |
394 | if ((Handle == NULL) || (ItemCount == NULL)) {\r | |
395 | return FALSE;\r | |
396 | }\r | |
397 | *ItemCount = 0;\r | |
398 | \r | |
399 | Status = gHiiDatabase->GetPackageListHandle (gHiiDatabase, Handle, &DriverHandle);\r | |
400 | if (EFI_ERROR (Status)) {\r | |
401 | return FALSE;\r | |
402 | }\r | |
403 | //\r | |
404 | // Get the device path by the got Driver handle .\r | |
405 | //\r | |
406 | Status = gBS->HandleProtocol (DriverHandle, &gEfiDevicePathProtocolGuid, (VOID **) &DevicePath);\r | |
407 | if (EFI_ERROR (Status)) {\r | |
408 | return FALSE;\r | |
409 | }\r | |
410 | TmpDevicePath = DevicePath;\r | |
411 | \r | |
412 | // \r | |
413 | // Check whether this device path include mac address device path.\r | |
414 | // If this path has mac address path, get the value whether need \r | |
415 | // add this info to the menu and return.\r | |
416 | // Else check more about the child handle devcie path.\r | |
417 | //\r | |
418 | if (IsMacAddressDevicePath(TmpDevicePath, NextShowFormId,&IsNeedAdd)) {\r | |
419 | if ((NETWORK_DEVICE_LIST_FORM_ID == NextShowFormId) && IsNeedAdd) {\r | |
420 | (*ItemCount) = 1;\r | |
421 | }\r | |
422 | return IsNeedAdd;\r | |
423 | }\r | |
424 | \r | |
425 | //\r | |
426 | // Search whether this path is the controller path, not he child handle path.\r | |
427 | // And the child handle has the network devcie connected.\r | |
428 | //\r | |
429 | TmpDevicePath = DevicePath;\r | |
430 | Status = gBS->LocateDevicePath(&gEfiDevicePathProtocolGuid, &TmpDevicePath, &ControllerHandle);\r | |
431 | if (EFI_ERROR (Status)) {\r | |
432 | return FALSE;\r | |
433 | }\r | |
434 | \r | |
435 | if (!IsDevicePathEnd (TmpDevicePath)) {\r | |
436 | return FALSE; \r | |
437 | }\r | |
438 | \r | |
439 | //\r | |
440 | // Retrieve the list of agents that are consuming the specific protocol\r | |
441 | // on ControllerHandle.\r | |
442 | // The buffer point by OpenInfoBuffer need be free at this function.\r | |
443 | //\r | |
444 | Status = gBS->OpenProtocolInformation (\r | |
445 | ControllerHandle,\r | |
446 | &gEfiPciIoProtocolGuid,\r | |
447 | &OpenInfoBuffer,\r | |
448 | &EntryCount\r | |
449 | );\r | |
450 | if (EFI_ERROR (Status)) {\r | |
451 | return FALSE;\r | |
452 | }\r | |
453 | \r | |
454 | //\r | |
455 | // Inspect if ChildHandle is one of the agents.\r | |
456 | //\r | |
457 | Status = EFI_UNSUPPORTED;\r | |
458 | for (Index = 0; Index < EntryCount; Index++) {\r | |
459 | //\r | |
460 | // Query all the children created by the controller handle's driver\r | |
461 | //\r | |
462 | if ((OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r | |
463 | Status = gBS->OpenProtocol (\r | |
464 | OpenInfoBuffer[Index].ControllerHandle,\r | |
465 | &gEfiDevicePathProtocolGuid,\r | |
466 | (VOID **) &ChildDevicePath,\r | |
467 | NULL,\r | |
468 | NULL,\r | |
469 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
470 | );\r | |
471 | if (EFI_ERROR (Status)) {\r | |
472 | continue;\r | |
473 | }\r | |
474 | \r | |
475 | // \r | |
476 | // Check whether this device path include mac address device path.\r | |
477 | //\r | |
478 | if (!IsMacAddressDevicePath(ChildDevicePath, NextShowFormId,&IsNeedAdd)) {\r | |
479 | //\r | |
480 | // If this path not has mac address path, check the other.\r | |
481 | //\r | |
482 | continue;\r | |
483 | } else {\r | |
484 | //\r | |
485 | // If need to update the NETWORK_DEVICE_LIST_FORM, try to get more.\r | |
486 | //\r | |
487 | if ((NETWORK_DEVICE_LIST_FORM_ID == NextShowFormId)) {\r | |
488 | if (IsNeedAdd) {\r | |
489 | (*ItemCount) += 1;\r | |
490 | }\r | |
491 | continue;\r | |
492 | } else {\r | |
493 | //\r | |
494 | // If need to update other form, return whether need to add to the menu.\r | |
495 | // \r | |
496 | goto Done;\r | |
497 | }\r | |
498 | }\r | |
499 | }\r | |
500 | }\r | |
501 | \r | |
502 | Done:\r | |
503 | if (OpenInfoBuffer != NULL) {\r | |
504 | FreePool (OpenInfoBuffer); \r | |
505 | }\r | |
506 | return IsNeedAdd; \r | |
507 | }\r | |
508 | \r | |
509 | /**\r | |
510 | This function registers HII packages to HII database.\r | |
511 | \r | |
512 | **/\r | |
513 | VOID\r | |
514 | InitializeDeviceManager (\r | |
515 | VOID\r | |
516 | )\r | |
517 | {\r | |
518 | EFI_STATUS Status;\r | |
519 | \r | |
520 | if (!gConnectAllHappened){\r | |
521 | EfiBootManagerConnectAll();\r | |
522 | gConnectAllHappened = TRUE;\r | |
523 | }\r | |
524 | \r | |
525 | gDeviceManagerPrivate.DriverHandle = NULL;\r | |
526 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
527 | &gDeviceManagerPrivate.DriverHandle,\r | |
528 | &gEfiDevicePathProtocolGuid,\r | |
529 | &mDeviceManagerHiiVendorDevicePath,\r | |
530 | &gEfiHiiConfigAccessProtocolGuid,\r | |
531 | &gDeviceManagerPrivate.ConfigAccess,\r | |
532 | NULL\r | |
533 | );\r | |
534 | ASSERT_EFI_ERROR (Status);\r | |
535 | \r | |
536 | //\r | |
537 | // Publish our HII data.\r | |
538 | //\r | |
539 | gDeviceManagerPrivate.HiiHandle = HiiAddPackages (\r | |
540 | &mDeviceManagerGuid,\r | |
541 | gDeviceManagerPrivate.DriverHandle,\r | |
542 | DeviceManagerVfrBin,\r | |
543 | UiAppStrings,\r | |
544 | NULL\r | |
545 | );\r | |
546 | ASSERT (gDeviceManagerPrivate.HiiHandle != NULL);\r | |
547 | }\r | |
548 | \r | |
549 | /**\r | |
550 | Remove the installed packages from the HII Database. \r | |
551 | \r | |
552 | **/\r | |
553 | VOID\r | |
554 | FreeDeviceManager(\r | |
555 | VOID\r | |
556 | )\r | |
557 | {\r | |
558 | EFI_STATUS Status;\r | |
559 | \r | |
560 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
561 | gDeviceManagerPrivate.DriverHandle,\r | |
562 | &gEfiDevicePathProtocolGuid,\r | |
563 | &mDeviceManagerHiiVendorDevicePath,\r | |
564 | &gEfiHiiConfigAccessProtocolGuid,\r | |
565 | &gDeviceManagerPrivate.ConfigAccess,\r | |
566 | NULL\r | |
567 | );\r | |
568 | ASSERT_EFI_ERROR (Status);\r | |
569 | \r | |
570 | HiiRemovePackages (gDeviceManagerPrivate.HiiHandle);\r | |
571 | }\r | |
572 | \r | |
573 | /**\r | |
574 | Dynamic create Hii information for Device Manager.\r | |
575 | \r | |
576 | @param NextShowFormId The FormId which need to be show.\r | |
577 | \r | |
578 | **/\r | |
579 | VOID\r | |
580 | CreateDeviceManagerForm(\r | |
581 | IN EFI_FORM_ID NextShowFormId\r | |
582 | )\r | |
583 | {\r | |
584 | UINTN Index;\r | |
585 | EFI_STRING String;\r | |
586 | EFI_STRING_ID Token;\r | |
587 | EFI_STRING_ID TokenHelp;\r | |
588 | EFI_HII_HANDLE *HiiHandles;\r | |
589 | EFI_HII_HANDLE HiiHandle;\r | |
590 | UINTN SkipCount;\r | |
591 | EFI_STRING_ID FormSetTitle;\r | |
592 | EFI_STRING_ID FormSetHelp;\r | |
593 | EFI_GUID FormSetGuid;\r | |
594 | VOID *StartOpCodeHandle;\r | |
595 | VOID *EndOpCodeHandle;\r | |
596 | EFI_IFR_GUID_LABEL *StartLabel;\r | |
597 | EFI_IFR_GUID_LABEL *EndLabel;\r | |
598 | BOOLEAN AddNetworkMenu;\r | |
599 | UINTN AddItemCount;\r | |
600 | UINTN NewStringLen;\r | |
601 | EFI_STRING NewStringTitle;\r | |
602 | CHAR16 *DevicePathStr;\r | |
603 | EFI_STRING_ID DevicePathId;\r | |
604 | \r | |
605 | HiiHandle = gDeviceManagerPrivate.HiiHandle;\r | |
606 | AddNetworkMenu = FALSE;\r | |
607 | AddItemCount = 0;\r | |
608 | \r | |
609 | //\r | |
610 | // If need show the Network device list form, clear the old save list first.\r | |
611 | //\r | |
612 | if ((NextShowFormId == NETWORK_DEVICE_LIST_FORM_ID) && (mMacDeviceList.CurListLen > 0)) {\r | |
613 | mMacDeviceList.CurListLen = 0;\r | |
614 | }\r | |
615 | \r | |
616 | //\r | |
617 | // Update the network device form titile.\r | |
618 | //\r | |
619 | if (NextShowFormId == NETWORK_DEVICE_FORM_ID) {\r | |
620 | String = HiiGetString (HiiHandle, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE), NULL);\r | |
621 | NewStringLen = StrLen(mSelectedMacAddrString) * 2;\r | |
622 | NewStringLen += (StrLen(String) + 2) * 2;\r | |
623 | NewStringTitle = AllocatePool (NewStringLen);\r | |
624 | UnicodeSPrint (NewStringTitle, NewStringLen, L"%s %s", String, mSelectedMacAddrString);\r | |
625 | HiiSetString (HiiHandle, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE), NewStringTitle, NULL); \r | |
626 | FreePool (String);\r | |
627 | FreePool (NewStringTitle);\r | |
628 | }\r | |
629 | \r | |
630 | //\r | |
631 | // Allocate space for creation of UpdateData Buffer\r | |
632 | //\r | |
633 | StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
634 | ASSERT (StartOpCodeHandle != NULL);\r | |
635 | \r | |
636 | EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
637 | ASSERT (EndOpCodeHandle != NULL);\r | |
638 | \r | |
639 | //\r | |
640 | // Create Hii Extend Label OpCode as the start opcode\r | |
641 | //\r | |
642 | StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r | |
643 | StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
644 | //\r | |
645 | // According to the next show Form id(mNextShowFormId) to decide which form need to update.\r | |
646 | //\r | |
647 | StartLabel->Number = (UINT16) (LABEL_FORM_ID_OFFSET + NextShowFormId);\r | |
648 | \r | |
649 | //\r | |
650 | // Create Hii Extend Label OpCode as the end opcode\r | |
651 | //\r | |
652 | EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r | |
653 | EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
654 | EndLabel->Number = LABEL_END;\r | |
655 | \r | |
656 | //\r | |
657 | // Get all the Hii handles\r | |
658 | //\r | |
659 | HiiHandles = HiiGetHiiHandles (NULL);\r | |
660 | ASSERT (HiiHandles != NULL);\r | |
661 | \r | |
662 | //\r | |
663 | // Search for formset of each class type\r | |
664 | //\r | |
665 | SkipCount = 0;\r | |
666 | for (Index = 0; HiiHandles[Index] != NULL; Index++) {\r | |
667 | //\r | |
668 | // The QuestionId in the form which will call the driver form has this asssumption.\r | |
669 | // QuestionId = Handle Index + NETWORK_DEVICE_LIST_KEY_OFFSET;\r | |
670 | // Different QuestionId at least has the section of NETWORK_DEVICE_LIST_KEY_OFFSET.\r | |
671 | //\r | |
672 | ASSERT(Index < MAX_KEY_SECTION_LEN);\r | |
673 | if (!ExtractDisplayedHiiFormFromHiiHandle (HiiHandles[Index], &gEfiHiiPlatformSetupFormsetGuid, SkipCount, &FormSetTitle, &FormSetHelp, &FormSetGuid)) {\r | |
674 | SkipCount = 0;\r | |
675 | continue;\r | |
676 | }\r | |
677 | \r | |
678 | String = HiiGetString (HiiHandles[Index], FormSetTitle, NULL);\r | |
679 | if (String == NULL) {\r | |
680 | String = HiiGetString (HiiHandle, STR_MISSING_STRING, NULL);\r | |
681 | ASSERT (String != NULL);\r | |
682 | }\r | |
683 | Token = HiiSetString (HiiHandle, 0, String, NULL);\r | |
684 | FreePool (String);\r | |
685 | \r | |
686 | String = HiiGetString (HiiHandles[Index], FormSetHelp, NULL);\r | |
687 | if (String == NULL) {\r | |
688 | String = HiiGetString (HiiHandle, STR_MISSING_STRING, NULL);\r | |
689 | ASSERT (String != NULL);\r | |
690 | }\r | |
691 | TokenHelp = HiiSetString (HiiHandle, 0, String, NULL);\r | |
692 | FreePool (String);\r | |
693 | \r | |
694 | //\r | |
695 | // Network device process\r | |
696 | // \r | |
697 | if (IsNeedAddNetworkMenu (HiiHandles[Index], NextShowFormId,&AddItemCount)) {\r | |
698 | if (NextShowFormId == DEVICE_MANAGER_FORM_ID) {\r | |
699 | //\r | |
700 | // Only show one menu item "Network Config" in the device manger form.\r | |
701 | //\r | |
702 | if (!AddNetworkMenu) {\r | |
703 | AddNetworkMenu = TRUE;\r | |
704 | HiiCreateGotoOpCode (\r | |
705 | StartOpCodeHandle,\r | |
706 | NETWORK_DEVICE_LIST_FORM_ID,\r | |
707 | STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_TITLE),\r | |
708 | STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_HELP),\r | |
709 | EFI_IFR_FLAG_CALLBACK,\r | |
710 | (EFI_QUESTION_ID) QUESTION_NETWORK_DEVICE_ID\r | |
711 | );\r | |
712 | }\r | |
713 | } else if (NextShowFormId == NETWORK_DEVICE_LIST_FORM_ID) {\r | |
714 | //\r | |
715 | // In network device list form, same mac address device only show one menu.\r | |
716 | //\r | |
717 | while (AddItemCount > 0) {\r | |
718 | HiiCreateGotoOpCode (\r | |
719 | StartOpCodeHandle,\r | |
720 | NETWORK_DEVICE_FORM_ID,\r | |
721 | mMacDeviceList.NodeList[mMacDeviceList.CurListLen - AddItemCount].PromptId,\r | |
722 | STRING_TOKEN (STR_NETWORK_DEVICE_HELP),\r | |
723 | EFI_IFR_FLAG_CALLBACK,\r | |
724 | mMacDeviceList.NodeList[mMacDeviceList.CurListLen - AddItemCount].QuestionId\r | |
725 | );\r | |
726 | AddItemCount -= 1;\r | |
727 | }\r | |
728 | } else if (NextShowFormId == NETWORK_DEVICE_FORM_ID) {\r | |
729 | //\r | |
730 | // In network device form, only the selected mac address device need to be show.\r | |
731 | //\r | |
732 | DevicePathStr = ExtractDevicePathFromHiiHandle(HiiHandles[Index]);\r | |
733 | DevicePathId = 0;\r | |
734 | if (DevicePathStr != NULL){\r | |
735 | DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL);\r | |
736 | FreePool(DevicePathStr);\r | |
737 | }\r | |
738 | HiiCreateGotoExOpCode (\r | |
739 | StartOpCodeHandle,\r | |
740 | 0,\r | |
741 | Token,\r | |
742 | TokenHelp,\r | |
743 | 0,\r | |
744 | (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET),\r | |
745 | 0,\r | |
746 | &FormSetGuid, \r | |
747 | DevicePathId\r | |
748 | );\r | |
749 | }\r | |
750 | } else {\r | |
751 | //\r | |
752 | // \r | |
753 | // Not network device process, only need to show at device manger form.\r | |
754 | //\r | |
755 | if (NextShowFormId == DEVICE_MANAGER_FORM_ID) {\r | |
756 | DevicePathStr = ExtractDevicePathFromHiiHandle(HiiHandles[Index]);\r | |
757 | DevicePathId = 0;\r | |
758 | if (DevicePathStr != NULL){\r | |
759 | DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL);\r | |
760 | FreePool(DevicePathStr);\r | |
761 | }\r | |
762 | HiiCreateGotoExOpCode (\r | |
763 | StartOpCodeHandle,\r | |
764 | 0,\r | |
765 | Token,\r | |
766 | TokenHelp,\r | |
767 | 0,\r | |
768 | (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET),\r | |
769 | 0,\r | |
770 | &FormSetGuid,\r | |
771 | DevicePathId\r | |
772 | );\r | |
773 | }\r | |
774 | }\r | |
775 | //\r | |
776 | //One packagelist may has more than one form package,\r | |
777 | //Index-- means keep current HiiHandle and still extract from the packagelist, \r | |
778 | //SkipCount++ means skip the formset which was found before in the same form package. \r | |
779 | //\r | |
780 | SkipCount++;\r | |
781 | Index--;\r | |
782 | }\r | |
783 | \r | |
784 | HiiUpdateForm (\r | |
785 | HiiHandle,\r | |
786 | &mDeviceManagerGuid,\r | |
787 | NextShowFormId,\r | |
788 | StartOpCodeHandle,\r | |
789 | EndOpCodeHandle\r | |
790 | );\r | |
791 | \r | |
792 | HiiFreeOpCodeHandle (StartOpCodeHandle);\r | |
793 | HiiFreeOpCodeHandle (EndOpCodeHandle);\r | |
794 | FreePool (HiiHandles);\r | |
795 | }\r | |
796 | \r |