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