]>
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 | |
350 | EFI_HII_HANDLE HiiDeviceManagerHandle;\r | |
351 | EFI_HANDLE DriverHandle;\r | |
352 | EFI_HANDLE ControllerHandle;\r | |
353 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
354 | EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;\r | |
355 | EFI_DEVICE_PATH_PROTOCOL *ChildDevicePath;\r | |
356 | EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r | |
357 | BOOLEAN IsNeedAdd;\r | |
358 | \r | |
359 | HiiDeviceManagerHandle = gDeviceManagerPrivate.HiiHandle;\r | |
360 | IsNeedAdd = FALSE;\r | |
361 | OpenInfoBuffer = NULL;\r | |
362 | if ((Handle == NULL) || (ItemCount == NULL)) {\r | |
363 | return FALSE;\r | |
364 | }\r | |
365 | *ItemCount = 0;\r | |
366 | \r | |
367 | Status = gHiiDatabase->GetPackageListHandle (gHiiDatabase, Handle, &DriverHandle);\r | |
368 | if (EFI_ERROR (Status)) {\r | |
369 | return FALSE;\r | |
370 | }\r | |
371 | //\r | |
372 | // Get the device path by the got Driver handle .\r | |
373 | //\r | |
374 | Status = gBS->HandleProtocol (DriverHandle, &gEfiDevicePathProtocolGuid, (VOID **) &DevicePath);\r | |
375 | if (EFI_ERROR (Status)) {\r | |
376 | return FALSE;\r | |
377 | }\r | |
378 | TmpDevicePath = DevicePath;\r | |
379 | \r | |
380 | // \r | |
381 | // Check whether this device path include mac address device path.\r | |
382 | // If this path has mac address path, get the value whether need \r | |
383 | // add this info to the menu and return.\r | |
384 | // Else check more about the child handle devcie path.\r | |
385 | //\r | |
386 | if (IsMacAddressDevicePath(TmpDevicePath, NextShowFormId,&IsNeedAdd)) {\r | |
387 | if ((NETWORK_DEVICE_LIST_FORM_ID == NextShowFormId) && IsNeedAdd) {\r | |
388 | (*ItemCount) = 1;\r | |
389 | }\r | |
390 | return IsNeedAdd;\r | |
391 | }\r | |
392 | \r | |
393 | //\r | |
394 | // Search whether this path is the controller path, not he child handle path.\r | |
395 | // And the child handle has the network devcie connected.\r | |
396 | //\r | |
397 | TmpDevicePath = DevicePath;\r | |
398 | Status = gBS->LocateDevicePath(&gEfiDevicePathProtocolGuid, &TmpDevicePath, &ControllerHandle);\r | |
399 | if (EFI_ERROR (Status)) {\r | |
400 | return FALSE;\r | |
401 | }\r | |
402 | \r | |
403 | if (!IsDevicePathEnd (TmpDevicePath)) {\r | |
404 | return FALSE; \r | |
405 | }\r | |
406 | \r | |
407 | //\r | |
408 | // Retrieve the list of agents that are consuming the specific protocol\r | |
409 | // on ControllerHandle.\r | |
410 | // The buffer point by OpenInfoBuffer need be free at this function.\r | |
411 | //\r | |
412 | Status = gBS->OpenProtocolInformation (\r | |
413 | ControllerHandle,\r | |
414 | &gEfiPciIoProtocolGuid,\r | |
415 | &OpenInfoBuffer,\r | |
416 | &EntryCount\r | |
417 | );\r | |
418 | if (EFI_ERROR (Status)) {\r | |
419 | return FALSE;\r | |
420 | }\r | |
421 | \r | |
422 | //\r | |
423 | // Inspect if ChildHandle is one of the agents.\r | |
424 | //\r | |
425 | Status = EFI_UNSUPPORTED;\r | |
426 | for (Index = 0; Index < EntryCount; Index++) {\r | |
427 | //\r | |
428 | // Query all the children created by the controller handle's driver\r | |
429 | //\r | |
430 | if ((OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r | |
431 | Status = gBS->OpenProtocol (\r | |
432 | OpenInfoBuffer[Index].ControllerHandle,\r | |
433 | &gEfiDevicePathProtocolGuid,\r | |
434 | (VOID **) &ChildDevicePath,\r | |
435 | NULL,\r | |
436 | NULL,\r | |
437 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
438 | );\r | |
439 | if (EFI_ERROR (Status)) {\r | |
440 | continue;\r | |
441 | }\r | |
442 | \r | |
443 | // \r | |
444 | // Check whether this device path include mac address device path.\r | |
445 | //\r | |
446 | if (!IsMacAddressDevicePath(ChildDevicePath, NextShowFormId,&IsNeedAdd)) {\r | |
447 | //\r | |
448 | // If this path not has mac address path, check the other.\r | |
449 | //\r | |
450 | continue;\r | |
451 | } else {\r | |
452 | //\r | |
453 | // If need to update the NETWORK_DEVICE_LIST_FORM, try to get more.\r | |
454 | //\r | |
455 | if ((NETWORK_DEVICE_LIST_FORM_ID == NextShowFormId)) {\r | |
456 | if (IsNeedAdd) {\r | |
457 | (*ItemCount) += 1;\r | |
458 | }\r | |
459 | continue;\r | |
460 | } else {\r | |
461 | //\r | |
462 | // If need to update other form, return whether need to add to the menu.\r | |
463 | // \r | |
464 | goto Done;\r | |
465 | }\r | |
466 | }\r | |
467 | }\r | |
468 | }\r | |
469 | \r | |
470 | Done:\r | |
471 | if (OpenInfoBuffer != NULL) {\r | |
472 | FreePool (OpenInfoBuffer); \r | |
473 | }\r | |
474 | return IsNeedAdd; \r | |
475 | }\r | |
476 | \r | |
477 | /**\r | |
478 | Dynamic create Hii information for Device Manager.\r | |
479 | \r | |
480 | @param NextShowFormId The FormId which need to be show.\r | |
481 | \r | |
482 | **/\r | |
483 | VOID\r | |
484 | CreateDeviceManagerForm(\r | |
485 | IN EFI_FORM_ID NextShowFormId\r | |
486 | )\r | |
487 | {\r | |
488 | UINTN Index;\r | |
489 | EFI_STRING String;\r | |
490 | EFI_STRING_ID Token;\r | |
491 | EFI_STRING_ID TokenHelp;\r | |
492 | EFI_HII_HANDLE *HiiHandles;\r | |
493 | EFI_HII_HANDLE HiiHandle;\r | |
494 | EFI_GUID FormSetGuid;\r | |
495 | VOID *StartOpCodeHandle;\r | |
496 | VOID *EndOpCodeHandle;\r | |
497 | EFI_IFR_GUID_LABEL *StartLabel;\r | |
498 | EFI_IFR_GUID_LABEL *EndLabel;\r | |
499 | BOOLEAN AddNetworkMenu;\r | |
500 | UINTN AddItemCount;\r | |
501 | UINTN NewStringLen;\r | |
502 | EFI_STRING NewStringTitle;\r | |
503 | CHAR16 *DevicePathStr;\r | |
504 | EFI_STRING_ID DevicePathId;\r | |
505 | EFI_IFR_FORM_SET *Buffer; \r | |
506 | UINTN BufferSize; \r | |
507 | UINT8 ClassGuidNum; \r | |
508 | EFI_GUID *ClassGuid; \r | |
509 | UINTN TempSize;\r | |
510 | UINT8 *Ptr;\r | |
511 | EFI_STATUS Status;\r | |
512 | \r | |
513 | TempSize =0;\r | |
514 | BufferSize = 0;\r | |
515 | Buffer = NULL;\r | |
516 | \r | |
517 | HiiHandle = gDeviceManagerPrivate.HiiHandle;\r | |
518 | AddNetworkMenu = FALSE;\r | |
519 | AddItemCount = 0;\r | |
520 | //\r | |
521 | // If need show the Network device list form, clear the old save list first.\r | |
522 | //\r | |
523 | if ((NextShowFormId == NETWORK_DEVICE_LIST_FORM_ID) && (mMacDeviceList.CurListLen > 0)) {\r | |
524 | mMacDeviceList.CurListLen = 0;\r | |
525 | }\r | |
526 | \r | |
527 | //\r | |
528 | // Update the network device form titile.\r | |
529 | //\r | |
530 | if (NextShowFormId == NETWORK_DEVICE_FORM_ID) {\r | |
531 | String = HiiGetString (HiiHandle, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE), NULL);\r | |
532 | NewStringLen = StrLen(mSelectedMacAddrString) * 2;\r | |
533 | NewStringLen += (StrLen(String) + 2) * 2;\r | |
534 | NewStringTitle = AllocatePool (NewStringLen);\r | |
535 | UnicodeSPrint (NewStringTitle, NewStringLen, L"%s %s", String, mSelectedMacAddrString);\r | |
536 | HiiSetString (HiiHandle, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE), NewStringTitle, NULL); \r | |
537 | FreePool (String);\r | |
538 | FreePool (NewStringTitle);\r | |
539 | }\r | |
540 | \r | |
541 | //\r | |
542 | // Allocate space for creation of UpdateData Buffer\r | |
543 | //\r | |
544 | StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
545 | ASSERT (StartOpCodeHandle != NULL);\r | |
546 | \r | |
547 | EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r | |
548 | ASSERT (EndOpCodeHandle != NULL);\r | |
549 | \r | |
550 | //\r | |
551 | // Create Hii Extend Label OpCode as the start opcode\r | |
552 | //\r | |
553 | StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r | |
554 | StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
555 | //\r | |
556 | // According to the next show Form id(mNextShowFormId) to decide which form need to update.\r | |
557 | //\r | |
558 | StartLabel->Number = (UINT16) (LABEL_FORM_ID_OFFSET + NextShowFormId);\r | |
559 | \r | |
560 | //\r | |
561 | // Create Hii Extend Label OpCode as the end opcode\r | |
562 | //\r | |
563 | EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r | |
564 | EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r | |
565 | EndLabel->Number = LABEL_END;\r | |
566 | \r | |
567 | //\r | |
568 | // Get all the Hii handles\r | |
569 | //\r | |
570 | HiiHandles = HiiGetHiiHandles (NULL);\r | |
571 | ASSERT (HiiHandles != NULL);\r | |
572 | \r | |
573 | //\r | |
574 | // Search for formset of each class type\r | |
575 | //\r | |
576 | for (Index = 0; HiiHandles[Index] != NULL; Index++) {\r | |
577 | Status = HiiGetFormSetFromHiiHandle(HiiHandles[Index], &Buffer,&BufferSize);\r | |
578 | if (EFI_ERROR (Status)){\r | |
579 | continue;\r | |
580 | }\r | |
581 | Ptr = (UINT8 *)Buffer;\r | |
582 | while(TempSize < BufferSize) {\r | |
583 | TempSize += ((EFI_IFR_OP_HEADER *) Ptr)->Length;\r | |
584 | if (((EFI_IFR_OP_HEADER *) Ptr)->Length <= OFFSET_OF (EFI_IFR_FORM_SET, Flags)){\r | |
585 | Ptr += ((EFI_IFR_OP_HEADER *) Ptr)->Length;\r | |
586 | continue;\r | |
587 | } \r | |
588 | \r | |
589 | ClassGuidNum = (UINT8) (((EFI_IFR_FORM_SET *)Ptr)->Flags & 0x3);\r | |
590 | ClassGuid = (EFI_GUID *) (VOID *)(Ptr + sizeof (EFI_IFR_FORM_SET));\r | |
591 | while (ClassGuidNum-- > 0) {\r | |
592 | if (CompareGuid (&gEfiHiiPlatformSetupFormsetGuid, ClassGuid)== 0) {\r | |
593 | ClassGuid ++;\r | |
594 | continue;\r | |
595 | }\r | |
596 | \r | |
597 | String = HiiGetString (HiiHandles[Index], ((EFI_IFR_FORM_SET *)Ptr)->FormSetTitle, NULL);\r | |
598 | if (String == NULL) {\r | |
599 | String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);\r | |
600 | ASSERT (String != NULL);\r | |
601 | }\r | |
602 | Token = HiiSetString (HiiHandle, 0, String, NULL);\r | |
603 | FreePool (String);\r | |
604 | \r | |
605 | String = HiiGetString (HiiHandles[Index], ((EFI_IFR_FORM_SET *)Ptr)->Help, NULL);\r | |
606 | if (String == NULL) {\r | |
607 | String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);\r | |
608 | ASSERT (String != NULL);\r | |
609 | }\r | |
610 | TokenHelp = HiiSetString (HiiHandle, 0, String, NULL);\r | |
611 | FreePool (String);\r | |
612 | \r | |
613 | FormSetGuid = ((EFI_IFR_FORM_SET *)Ptr)->Guid;\r | |
614 | \r | |
615 | //\r | |
616 | // Network device process\r | |
617 | // \r | |
618 | if (IsNeedAddNetworkMenu (HiiHandles[Index], NextShowFormId,&AddItemCount)) {\r | |
619 | if (NextShowFormId == DEVICE_MANAGER_FORM_ID) {\r | |
620 | //\r | |
621 | // Only show one menu item "Network Config" in the device manger form.\r | |
622 | //\r | |
623 | if (!AddNetworkMenu) {\r | |
624 | AddNetworkMenu = TRUE;\r | |
625 | HiiCreateGotoOpCode (\r | |
626 | StartOpCodeHandle,\r | |
627 | NETWORK_DEVICE_LIST_FORM_ID,\r | |
628 | STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_TITLE),\r | |
629 | STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_HELP),\r | |
630 | EFI_IFR_FLAG_CALLBACK,\r | |
631 | (EFI_QUESTION_ID) QUESTION_NETWORK_DEVICE_ID\r | |
632 | );\r | |
633 | }\r | |
634 | } else if (NextShowFormId == NETWORK_DEVICE_LIST_FORM_ID) {\r | |
635 | //\r | |
636 | // In network device list form, same mac address device only show one menu.\r | |
637 | //\r | |
638 | while (AddItemCount > 0) {\r | |
639 | HiiCreateGotoOpCode (\r | |
640 | StartOpCodeHandle,\r | |
641 | NETWORK_DEVICE_FORM_ID,\r | |
642 | mMacDeviceList.NodeList[mMacDeviceList.CurListLen - AddItemCount].PromptId,\r | |
643 | STRING_TOKEN (STR_NETWORK_DEVICE_HELP),\r | |
644 | EFI_IFR_FLAG_CALLBACK,\r | |
645 | mMacDeviceList.NodeList[mMacDeviceList.CurListLen - AddItemCount].QuestionId\r | |
646 | );\r | |
647 | AddItemCount -= 1;\r | |
648 | }\r | |
649 | } else if (NextShowFormId == NETWORK_DEVICE_FORM_ID) {\r | |
650 | //\r | |
651 | // In network device form, only the selected mac address device need to be show.\r | |
652 | //\r | |
653 | DevicePathStr = DmExtractDevicePathFromHiiHandle(HiiHandles[Index]);\r | |
654 | DevicePathId = 0;\r | |
655 | if (DevicePathStr != NULL){\r | |
656 | DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL);\r | |
657 | FreePool(DevicePathStr);\r | |
658 | }\r | |
659 | HiiCreateGotoExOpCode (\r | |
660 | StartOpCodeHandle,\r | |
661 | 0,\r | |
662 | Token,\r | |
663 | TokenHelp,\r | |
664 | 0,\r | |
665 | (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET),\r | |
666 | 0,\r | |
667 | &FormSetGuid, \r | |
668 | DevicePathId\r | |
669 | );\r | |
670 | }\r | |
671 | } else {\r | |
672 | //\r | |
673 | // Not network device process, only need to show at device manger form.\r | |
674 | //\r | |
675 | if (NextShowFormId == DEVICE_MANAGER_FORM_ID) {\r | |
676 | DevicePathStr = DmExtractDevicePathFromHiiHandle(HiiHandles[Index]);\r | |
677 | DevicePathId = 0;\r | |
678 | if (DevicePathStr != NULL){\r | |
679 | DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL);\r | |
680 | FreePool(DevicePathStr);\r | |
681 | }\r | |
682 | HiiCreateGotoExOpCode (\r | |
683 | StartOpCodeHandle,\r | |
684 | 0,\r | |
685 | Token,\r | |
686 | TokenHelp,\r | |
687 | 0,\r | |
688 | (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET),\r | |
689 | 0,\r | |
690 | &FormSetGuid,\r | |
691 | DevicePathId\r | |
692 | );\r | |
693 | }\r | |
694 | }\r | |
695 | break;\r | |
696 | }\r | |
697 | \r | |
698 | Ptr += ((EFI_IFR_OP_HEADER *) Ptr)->Length;\r | |
699 | }\r | |
700 | FreePool(Buffer);\r | |
701 | Buffer = NULL;\r | |
702 | TempSize = 0;\r | |
703 | BufferSize = 0;\r | |
704 | }\r | |
705 | \r | |
706 | HiiUpdateForm (\r | |
707 | HiiHandle,\r | |
708 | &mDeviceManagerGuid,\r | |
709 | NextShowFormId,\r | |
710 | StartOpCodeHandle,\r | |
711 | EndOpCodeHandle\r | |
712 | );\r | |
713 | \r | |
714 | HiiFreeOpCodeHandle (StartOpCodeHandle);\r | |
715 | HiiFreeOpCodeHandle (EndOpCodeHandle);\r | |
716 | FreePool (HiiHandles);\r | |
717 | }\r | |
718 | \r | |
719 | /**\r | |
720 | This function allows a caller to extract the current configuration for one\r | |
721 | or more named elements from the target driver.\r | |
722 | \r | |
723 | \r | |
724 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
725 | @param Request A null-terminated Unicode string in <ConfigRequest> format.\r | |
726 | @param Progress On return, points to a character in the Request string.\r | |
727 | Points to the string's null terminator if request was successful.\r | |
728 | Points to the most recent '&' before the first failing name/value\r | |
729 | pair (or the beginning of the string if the failure is in the\r | |
730 | first name/value pair) if the request was not successful.\r | |
731 | @param Results A null-terminated Unicode string in <ConfigAltResp> format which\r | |
732 | has all values filled in for the names in the Request string.\r | |
733 | String to be allocated by the called function.\r | |
734 | \r | |
735 | @retval EFI_SUCCESS The Results is filled with the requested values.\r | |
736 | @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r | |
737 | @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r | |
738 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r | |
739 | \r | |
740 | **/\r | |
741 | EFI_STATUS\r | |
742 | EFIAPI\r | |
743 | DeviceManagerExtractConfig (\r | |
744 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
745 | IN CONST EFI_STRING Request,\r | |
746 | OUT EFI_STRING *Progress,\r | |
747 | OUT EFI_STRING *Results\r | |
748 | )\r | |
749 | {\r | |
750 | if (Progress == NULL || Results == NULL) {\r | |
751 | return EFI_INVALID_PARAMETER;\r | |
752 | }\r | |
753 | *Progress = Request;\r | |
754 | return EFI_NOT_FOUND;\r | |
755 | }\r | |
756 | \r | |
757 | /**\r | |
758 | This function processes the results of changes in configuration.\r | |
759 | \r | |
760 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
761 | @param Configuration A null-terminated Unicode string in <ConfigResp> format.\r | |
762 | @param Progress A pointer to a string filled in with the offset of the most\r | |
763 | recent '&' before the first failing name/value pair (or the\r | |
764 | beginning of the string if the failure is in the first\r | |
765 | name/value pair) or the terminating NULL if all was successful.\r | |
766 | \r | |
767 | @retval EFI_SUCCESS The Results is processed successfully.\r | |
768 | @retval EFI_INVALID_PARAMETER Configuration is NULL.\r | |
769 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r | |
770 | \r | |
771 | **/\r | |
772 | EFI_STATUS\r | |
773 | EFIAPI\r | |
774 | DeviceManagerRouteConfig (\r | |
775 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
776 | IN CONST EFI_STRING Configuration,\r | |
777 | OUT EFI_STRING *Progress\r | |
778 | )\r | |
779 | {\r | |
780 | if (Configuration == NULL || Progress == NULL) {\r | |
781 | return EFI_INVALID_PARAMETER;\r | |
782 | }\r | |
783 | \r | |
784 | *Progress = Configuration;\r | |
785 | \r | |
786 | return EFI_NOT_FOUND;\r | |
787 | }\r | |
788 | \r | |
789 | /**\r | |
790 | This function is invoked if user selected a interactive opcode from Device Manager's\r | |
791 | Formset. If user set VBIOS, the new value is saved to EFI variable.\r | |
792 | \r | |
793 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
794 | @param Action Specifies the type of action taken by the browser.\r | |
795 | @param QuestionId A unique value which is sent to the original exporting driver\r | |
796 | so that it can identify the type of data to expect.\r | |
797 | @param Type The type of value for the question.\r | |
798 | @param Value A pointer to the data being sent to the original exporting driver.\r | |
799 | @param ActionRequest On return, points to the action requested by the callback function.\r | |
800 | \r | |
801 | @retval EFI_SUCCESS The callback successfully handled the action.\r | |
802 | @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.\r | |
803 | \r | |
804 | **/\r | |
805 | EFI_STATUS\r | |
806 | EFIAPI\r | |
807 | DeviceManagerCallback (\r | |
808 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
809 | IN EFI_BROWSER_ACTION Action,\r | |
810 | IN EFI_QUESTION_ID QuestionId,\r | |
811 | IN UINT8 Type,\r | |
812 | IN EFI_IFR_TYPE_VALUE *Value,\r | |
813 | OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r | |
814 | )\r | |
815 | {\r | |
816 | UINTN CurIndex;\r | |
817 | \r | |
818 | if (Action != EFI_BROWSER_ACTION_CHANGING) {\r | |
819 | //\r | |
820 | // Do nothing for other UEFI Action. Only do call back when data is changed.\r | |
821 | //\r | |
822 | return EFI_UNSUPPORTED;\r | |
823 | }\r | |
824 | if ((Value == NULL) || (ActionRequest == NULL)) {\r | |
825 | return EFI_INVALID_PARAMETER;\r | |
826 | }\r | |
827 | if ((QuestionId < MAX_KEY_SECTION_LEN + NETWORK_DEVICE_LIST_KEY_OFFSET) && (QuestionId >= NETWORK_DEVICE_LIST_KEY_OFFSET)) {\r | |
828 | //\r | |
829 | // If user select the mac address, need to record mac address string to support next form show.\r | |
830 | //\r | |
831 | for (CurIndex = 0; CurIndex < mMacDeviceList.CurListLen; CurIndex ++) {\r | |
832 | if (mMacDeviceList.NodeList[CurIndex].QuestionId == QuestionId) {\r | |
833 | mSelectedMacAddrString = HiiGetString (gDeviceManagerPrivate.HiiHandle, mMacDeviceList.NodeList[CurIndex].PromptId, NULL);\r | |
834 | }\r | |
835 | }\r | |
836 | CreateDeviceManagerForm(NETWORK_DEVICE_FORM_ID);\r | |
837 | } else if(QuestionId == QUESTION_NETWORK_DEVICE_ID){\r | |
838 | CreateDeviceManagerForm(NETWORK_DEVICE_LIST_FORM_ID);\r | |
839 | }\r | |
840 | \r | |
841 | return EFI_SUCCESS;\r | |
842 | }\r | |
843 | \r | |
844 | /**\r | |
845 | Install Boot Manager Menu driver.\r | |
846 | \r | |
847 | @param ImageHandle The image handle.\r | |
848 | @param SystemTable The system table.\r | |
849 | \r | |
850 | @retval EFI_SUCEESS Install Boot manager menu success.\r | |
851 | @retval Other Return error status.\r | |
852 | \r | |
853 | **/\r | |
854 | EFI_STATUS\r | |
855 | EFIAPI\r | |
856 | DeviceManagerLibConstructor (\r | |
857 | IN EFI_HANDLE ImageHandle,\r | |
858 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
859 | )\r | |
860 | {\r | |
861 | EFI_STATUS Status;\r | |
862 | \r | |
863 | gDeviceManagerPrivate.DriverHandle = NULL;\r | |
864 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
865 | &gDeviceManagerPrivate.DriverHandle,\r | |
866 | &gEfiDevicePathProtocolGuid,\r | |
867 | &mDeviceManagerHiiVendorDevicePath,\r | |
868 | &gEfiHiiConfigAccessProtocolGuid,\r | |
869 | &gDeviceManagerPrivate.ConfigAccess,\r | |
870 | NULL\r | |
871 | );\r | |
872 | ASSERT_EFI_ERROR (Status);\r | |
873 | \r | |
874 | //\r | |
875 | // Publish our HII data.\r | |
876 | //\r | |
877 | gDeviceManagerPrivate.HiiHandle = HiiAddPackages (\r | |
878 | &mDeviceManagerGuid,\r | |
879 | gDeviceManagerPrivate.DriverHandle,\r | |
880 | DeviceManagerVfrBin,\r | |
881 | DeviceManagerLibStrings,\r | |
882 | NULL\r | |
883 | );\r | |
884 | ASSERT (gDeviceManagerPrivate.HiiHandle != NULL);\r | |
885 | \r | |
886 | //\r | |
887 | // Update boot manager page \r | |
888 | //\r | |
889 | CreateDeviceManagerForm (DEVICE_MANAGER_FORM_ID);\r | |
890 | \r | |
891 | return EFI_SUCCESS;\r | |
892 | }\r | |
893 | \r | |
894 | /**\r | |
895 | Unloads the application and its installed protocol.\r | |
896 | \r | |
897 | @param ImageHandle Handle that identifies the image to be unloaded.\r | |
898 | @param SystemTable The system table.\r | |
899 | \r | |
900 | @retval EFI_SUCCESS The image has been unloaded.\r | |
901 | **/\r | |
902 | EFI_STATUS\r | |
903 | EFIAPI\r | |
904 | DeviceManagerLibDestructor(\r | |
905 | IN EFI_HANDLE ImageHandle,\r | |
906 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
907 | )\r | |
908 | {\r | |
909 | EFI_STATUS Status;\r | |
910 | \r | |
911 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
912 | gDeviceManagerPrivate.DriverHandle,\r | |
913 | &gEfiDevicePathProtocolGuid,\r | |
914 | &mDeviceManagerHiiVendorDevicePath,\r | |
915 | &gEfiHiiConfigAccessProtocolGuid,\r | |
916 | &gDeviceManagerPrivate.ConfigAccess,\r | |
917 | NULL\r | |
918 | );\r | |
919 | ASSERT_EFI_ERROR (Status);\r | |
920 | \r | |
921 | HiiRemovePackages (gDeviceManagerPrivate.HiiHandle);\r | |
922 | \r | |
923 | return EFI_SUCCESS;\r | |
924 | }\r | |
925 | \r |