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