]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/UserIdentification/UsbCredentialProviderDxe/UsbCredentialProvider.c
Update UID drivers to align with latest UEFI spec 2.3.1.
[mirror_edk2.git] / SecurityPkg / UserIdentification / UsbCredentialProviderDxe / UsbCredentialProvider.c
CommitLineData
0c18794e 1/** @file\r
2 Usb Credential Provider driver implemenetation.\r
3 \r
ae4cb94f 4Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
0c18794e 5This program and the accompanying materials \r
6are licensed and made available under the terms and conditions of the BSD License \r
7which accompanies this distribution. The full text of the license may be found at \r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "UsbCredentialProvider.h"\r
16\r
17CREDENTIAL_TABLE *mUsbTable = NULL;\r
18USB_PROVIDER_CALLBACK_INFO *mCallbackInfo = NULL;\r
19USB_CREDENTIAL_INFO *mUsbInfoHandle = NULL;\r
20\r
6f0b8648 21EFI_USER_CREDENTIAL2_PROTOCOL gUsbCredentialProviderDriver = {\r
0c18794e 22 USB_CREDENTIAL_PROVIDER_GUID,\r
23 EFI_USER_CREDENTIAL_CLASS_SECURE_CARD,\r
24 CredentialEnroll,\r
25 CredentialForm,\r
26 CredentialTile,\r
27 CredentialTitle,\r
28 CredentialUser,\r
29 CredentialSelect,\r
30 CredentialDeselect,\r
31 CredentialDefault,\r
32 CredentialGetInfo,\r
6f0b8648 33 CredentialGetNextInfo,\r
34 EFI_CREDENTIAL_CAPABILITIES_ENROLL,\r
35 CredentialDelete\r
0c18794e 36};\r
37\r
38\r
39/**\r
40 Get string by string id from HII Interface.\r
41\r
42\r
43 @param[in] Id String ID to get the string from.\r
44\r
45 @retval CHAR16 * String from ID.\r
46 @retval NULL If error occurs.\r
47\r
48**/\r
49CHAR16 *\r
50GetStringById (\r
51 IN EFI_STRING_ID Id\r
52 )\r
53{\r
54 //\r
55 // Get the current string for the current Language\r
56 //\r
57 return HiiGetString (mCallbackInfo->HiiHandle, Id, NULL);\r
58}\r
59\r
60\r
61/**\r
62 Expand password table size.\r
63\r
64**/\r
65VOID\r
66ExpandTableSize (\r
67 VOID\r
68 )\r
69{\r
70 CREDENTIAL_TABLE *NewTable;\r
71 UINTN Count;\r
72\r
73 Count = mUsbTable->MaxCount + USB_TABLE_INC;\r
74 //\r
75 // Create new credential table.\r
76 //\r
77 NewTable = AllocateZeroPool (\r
78 sizeof (CREDENTIAL_TABLE) - sizeof (USB_INFO) +\r
79 Count * sizeof (USB_INFO)\r
80 );\r
81 ASSERT (NewTable != NULL); \r
82\r
83 NewTable->MaxCount = Count;\r
84 NewTable->Count = mUsbTable->Count;\r
85\r
86 //\r
87 // Copy old entries.\r
88 //\r
89 CopyMem (\r
90 &NewTable->UserInfo, \r
91 &mUsbTable->UserInfo, \r
92 mUsbTable->Count * sizeof (USB_INFO)\r
93 );\r
94 FreePool (mUsbTable);\r
95 mUsbTable = NewTable;\r
96}\r
97\r
98\r
99/**\r
6f0b8648 100 Add, update or delete info in table, and sync with NV variable.\r
0c18794e 101\r
6f0b8648 102 @param[in] Index The index of the password in table. If index is found in\r
103 table, update the info, else add the into to table. \r
104 @param[in] Info The new credential info to add into table. If Info is NULL, \r
105 delete the info by Index.\r
0c18794e 106\r
107 @retval EFI_INVALID_PARAMETER Info is NULL when save the info.\r
108 @retval EFI_SUCCESS Modify the table successfully.\r
109 @retval Others Failed to modify the table.\r
110\r
111**/\r
112EFI_STATUS\r
113ModifyTable (\r
114 IN UINTN Index,\r
115 IN USB_INFO * Info OPTIONAL\r
116 )\r
117{\r
118 EFI_STATUS Status;\r
6f0b8648 119 USB_INFO *NewUsbInfo;\r
0c18794e 120 \r
6f0b8648 121 NewUsbInfo = NULL;\r
0c18794e 122 if (Index < mUsbTable->Count) {\r
6f0b8648 123 if (Info == NULL) {\r
124 //\r
125 // Delete the specified entry.\r
126 //\r
127 mUsbTable->Count--;\r
128 if (Index != mUsbTable->Count) {\r
129 NewUsbInfo = &mUsbTable->UserInfo[mUsbTable->Count];\r
130 } \r
131 } else {\r
132 //\r
133 // Update the specified entry.\r
134 //\r
135 NewUsbInfo = Info;\r
0c18794e 136 }\r
137 } else {\r
138 //\r
139 // Add a new entry\r
140 //\r
141 if (Info == NULL) {\r
142 return EFI_INVALID_PARAMETER;\r
143 }\r
144\r
145 if (mUsbTable->Count >= mUsbTable->MaxCount) {\r
146 ExpandTableSize ();\r
147 }\r
148\r
6f0b8648 149 NewUsbInfo = Info;\r
0c18794e 150 mUsbTable->Count++;\r
151 }\r
152\r
6f0b8648 153 if (NewUsbInfo != NULL) {\r
154 CopyMem (&mUsbTable->UserInfo[Index], NewUsbInfo, sizeof (USB_INFO));\r
155 }\r
156\r
0c18794e 157 //\r
158 // Save the credential table.\r
159 //\r
160 Status = gRT->SetVariable (\r
161 L"UsbCredential",\r
a0c56a82 162 &gUsbCredentialProviderGuid,\r
0c18794e 163 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
164 mUsbTable->Count * sizeof (USB_INFO),\r
165 &mUsbTable->UserInfo\r
166 );\r
167 return Status;\r
168}\r
169\r
170\r
171/**\r
172 Create a credential table\r
173\r
174 @retval EFI_SUCCESS Create a credential table successfully.\r
175 @retval Others Failed to create a password.\r
176\r
177**/\r
178EFI_STATUS\r
179InitCredentialTable (\r
180 VOID\r
181 )\r
182{\r
183 EFI_STATUS Status;\r
184 UINT8 *Var;\r
185 UINTN VarSize;\r
186\r
187 //\r
188 // Get Usb credential data from NV variable.\r
189 //\r
190 VarSize = 0;\r
191 Var = NULL;\r
192 Status = gRT->GetVariable (\r
193 L"UsbCredential", \r
a0c56a82 194 &gUsbCredentialProviderGuid, \r
0c18794e 195 NULL, \r
196 &VarSize,\r
197 Var\r
198 );\r
199 if (Status == EFI_BUFFER_TOO_SMALL) {\r
200 Var = AllocateZeroPool (VarSize);\r
201 if (Var == NULL) {\r
202 return EFI_OUT_OF_RESOURCES;\r
203 }\r
204 Status = gRT->GetVariable (\r
205 L"UsbCredential", \r
a0c56a82 206 &gUsbCredentialProviderGuid, \r
0c18794e 207 NULL, \r
208 &VarSize,\r
209 Var\r
210 );\r
211 }\r
212 if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {\r
213 return Status;\r
214 }\r
215 \r
216 //\r
217 // Init Usb credential table.\r
218 //\r
219 mUsbTable = AllocateZeroPool (\r
220 sizeof (CREDENTIAL_TABLE) - sizeof (USB_INFO) +\r
221 USB_TABLE_INC * sizeof (USB_INFO) + \r
222 VarSize\r
223 );\r
224 if (mUsbTable == NULL) {\r
225 FreePool (Var);\r
226 return EFI_OUT_OF_RESOURCES;\r
227 }\r
228\r
229 mUsbTable->Count = VarSize / sizeof (USB_INFO);\r
230 mUsbTable->MaxCount = mUsbTable->Count + USB_TABLE_INC;\r
231 if (Var != NULL) {\r
232 CopyMem (mUsbTable->UserInfo, Var, VarSize);\r
233 FreePool (Var);\r
234 }\r
235 return EFI_SUCCESS;\r
236}\r
237\r
238\r
239/**\r
240 Read the specified file by FileName in the Usb key and return the file size in BufferSize\r
241 and file content in Buffer.\r
242 Note: the caller is responsible to free the buffer memory.\r
243\r
244 @param FileName File to read.\r
245 @param Buffer Returned with data read from the file.\r
246 @param BufferSize Size of the data buffer.\r
247\r
248 @retval EFI_SUCCESS The command completed successfully.\r
249 @retval EFI_OUT_OF_RESOURCES Resource allocation failed.\r
250 @retval EFI_NOT_FOUND File not found.\r
251 @retval EFI_DEVICE_ERROR Device I/O error.\r
252\r
253**/\r
254EFI_STATUS\r
255GetFileData (\r
256 IN CHAR16 *FileName,\r
257 OUT VOID **Buffer,\r
258 OUT UINTN *BufferSize\r
259 )\r
260{\r
261 EFI_STATUS Status;\r
262 UINTN Index;\r
263 UINTN HandleCount;\r
264 UINTN ScratchBufferSize;\r
265 EFI_HANDLE *HandleBuffer;\r
266 EFI_FILE *RootFs;\r
267 EFI_FILE *FileHandle;\r
268 EFI_FILE_INFO *FileInfo;\r
269 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;\r
270 EFI_BLOCK_IO_PROTOCOL *BlkIo;\r
271\r
272 FileInfo = NULL;\r
273 FileHandle = NULL;\r
274\r
275 Status = gBS->LocateHandleBuffer (\r
276 ByProtocol,\r
277 &gEfiSimpleFileSystemProtocolGuid,\r
278 NULL,\r
279 &HandleCount,\r
280 &HandleBuffer\r
281 );\r
282 if (EFI_ERROR (Status)) {\r
283 DEBUG ((DEBUG_ERROR, "Can not Locate SimpleFileSystemProtocol\n"));\r
284 goto Done;\r
285 }\r
286\r
287 //\r
288 // Find and open the file in removable media disk.\r
289 //\r
290 for (Index = 0; Index < HandleCount; Index++) {\r
291 Status = gBS->HandleProtocol (\r
292 HandleBuffer[Index],\r
293 &gEfiBlockIoProtocolGuid,\r
294 (VOID **) &BlkIo\r
295 );\r
296 if (EFI_ERROR (Status)) {\r
297 continue;\r
298 }\r
299\r
300 if (BlkIo->Media->RemovableMedia) {\r
301 Status = gBS->HandleProtocol (\r
302 HandleBuffer[Index],\r
303 &gEfiSimpleFileSystemProtocolGuid,\r
304 (VOID **) &SimpleFileSystem\r
305 );\r
306 if (EFI_ERROR (Status)) {\r
307 continue;\r
308 }\r
309 \r
310 Status = SimpleFileSystem->OpenVolume (\r
311 SimpleFileSystem,\r
312 &RootFs\r
313 );\r
314 if (EFI_ERROR (Status)) {\r
315 continue;\r
316 }\r
317 \r
318 Status = RootFs->Open (\r
319 RootFs,\r
320 &FileHandle,\r
321 FileName,\r
322 EFI_FILE_MODE_READ,\r
323 0\r
324 );\r
325 if (!EFI_ERROR (Status)) {\r
326 break;\r
327 } \r
328 }\r
329 }\r
330\r
331 FreePool (HandleBuffer);\r
332\r
333 if (Index >= HandleCount) {\r
334 DEBUG ((DEBUG_ERROR, "Can not found the token file!\n"));\r
335 Status = EFI_NOT_FOUND;\r
336 goto Done;\r
337 }\r
338 \r
339 //\r
340 // Figure out how big the file is.\r
341 //\r
342 ScratchBufferSize = 0;\r
343 Status = FileHandle->GetInfo (\r
344 FileHandle,\r
345 &gEfiFileInfoGuid,\r
346 &ScratchBufferSize,\r
347 NULL\r
348 );\r
349 if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {\r
350 DEBUG ((DEBUG_ERROR, "Can not obtain file size info!\n"));\r
351 Status = EFI_DEVICE_ERROR;\r
352 goto Done;\r
353 }\r
354\r
355 FileInfo = AllocateZeroPool (ScratchBufferSize); \r
356 if (FileInfo == NULL) {\r
357 DEBUG ((DEBUG_ERROR, "Can not allocate enough memory for the token file!\n"));\r
358 Status = EFI_OUT_OF_RESOURCES;\r
359 goto Done;\r
360 }\r
361\r
362 Status = FileHandle->GetInfo (\r
363 FileHandle,\r
364 &gEfiFileInfoGuid,\r
365 &ScratchBufferSize,\r
366 FileInfo\r
367 );\r
368 if (EFI_ERROR (Status)) {\r
369 DEBUG ((DEBUG_ERROR, "Can not obtain file info from the token file!\n"));\r
370 Status = EFI_DEVICE_ERROR;\r
371 goto Done;\r
372 }\r
373 \r
374 //\r
375 // Allocate a buffer for the file.\r
376 //\r
377 *BufferSize = (UINT32) FileInfo->FileSize;\r
378 *Buffer = AllocateZeroPool (*BufferSize); \r
379 if (*Buffer == NULL) {\r
380 DEBUG ((DEBUG_ERROR, "Can not allocate a buffer for the file!\n"));\r
381 Status = EFI_OUT_OF_RESOURCES;\r
382 goto Done;\r
383 }\r
384 \r
385 //\r
386 // Load file into the allocated memory.\r
387 //\r
388 Status = FileHandle->Read (FileHandle, BufferSize, *Buffer);\r
389 if (EFI_ERROR (Status)) {\r
390 FreePool (*Buffer);\r
391 DEBUG ((DEBUG_ERROR, "Can not read the token file!\n"));\r
392 Status = EFI_DEVICE_ERROR;\r
393 goto Done;\r
394 }\r
395 \r
396 //\r
397 // Close file.\r
398 //\r
399 Status = FileHandle->Close (FileHandle);\r
400 if (EFI_ERROR (Status)) {\r
401 FreePool (*Buffer);\r
402 DEBUG ((DEBUG_ERROR, "Can not close the token file !\n"));\r
403 Status = EFI_DEVICE_ERROR;\r
404 }\r
405\r
406Done:\r
407\r
408 if (FileInfo != NULL) {\r
409 FreePool (FileInfo);\r
410 }\r
411\r
412 return Status;\r
413}\r
414\r
415\r
416/**\r
417 Hash the data to get credential.\r
418\r
419 @param[in] Buffer Points to the data buffer \r
420 @param[in] BufferSize The size of data in buffer, in bytes.\r
421 @param[out] Credential Points to the hashed result\r
422\r
423 @retval TRUE Hash the data successfully.\r
424 @retval FALSE Failed to hash the data.\r
425 \r
426**/\r
427BOOLEAN\r
428GenerateCredential (\r
429 IN UINT8 *Buffer,\r
430 IN UINTN BufferSize,\r
431 OUT UINT8 *Credential\r
432 )\r
433{\r
434 BOOLEAN Status;\r
435 UINTN HashSize;\r
436 VOID *Hash;\r
437 \r
438 HashSize = Sha1GetContextSize ();\r
439 Hash = AllocatePool (HashSize);\r
440 ASSERT (Hash != NULL);\r
441 \r
442 Status = Sha1Init (Hash);\r
443 if (!Status) {\r
444 goto Done;\r
445 }\r
446 \r
447 Status = Sha1Update (Hash, Buffer, BufferSize);\r
448 if (!Status) {\r
449 goto Done;\r
450 }\r
451 \r
452 Status = Sha1Final (Hash, Credential);\r
453 \r
454Done:\r
455 FreePool (Hash);\r
456 return Status;\r
457}\r
458\r
459\r
460/**\r
461 Read the token file, and default the Token is saved at the begining of the file.\r
462\r
463 @param[out] Token Token read from a Token file.\r
464\r
465 @retval EFI_SUCCESS Read a Token successfully.\r
466 @retval Others Fails to read a Token.\r
467 \r
468**/\r
469EFI_STATUS\r
470GetToken (\r
471 OUT UINT8 *Token\r
472 )\r
473{\r
474 EFI_STATUS Status;\r
475 UINT8 *Buffer;\r
476 UINTN BufSize;\r
477 CHAR16 *TokenFile;\r
478\r
479 BufSize = 0;\r
480 Buffer = NULL;\r
481 TokenFile = FixedPcdGetPtr (PcdFixedUsbCredentialProviderTokenFileName);\r
482 Status = GetFileData (TokenFile, (VOID *)&Buffer, &BufSize);\r
483 if (EFI_ERROR (Status)) {\r
484 DEBUG ((DEBUG_ERROR, "Read file %s from USB error! Status=(%r)\n", TokenFile, Status));\r
485 return Status;\r
486 }\r
487 \r
488 if (!GenerateCredential (Buffer, BufSize, Token)) {\r
489 DEBUG ((DEBUG_ERROR, "Generate credential from read data failed!\n"));\r
490 FreePool (Buffer);\r
491 return EFI_SECURITY_VIOLATION;\r
492 }\r
493 \r
494 FreePool (Buffer); \r
495 return EFI_SUCCESS;\r
496}\r
497\r
498\r
499/**\r
500 Find a user infomation record by the information record type.\r
501\r
502 This function searches all user information records of User from beginning \r
503 until either the information is found or there are no more user infomation\r
504 record. A match occurs when a Info.InfoType field matches the user information\r
505 record type.\r
506\r
507 @param[in] User Points to the user profile record to search. \r
508 @param[in] InfoType The infomation type to be searched.\r
509 @param[out] Info Points to the user info found, the caller is responsible\r
510 to free.\r
511 \r
512 @retval EFI_SUCCESS Find the user information successfully.\r
513 @retval Others Fail to find the user information.\r
514\r
515**/\r
516EFI_STATUS\r
517FindUserInfoByType (\r
518 IN EFI_USER_PROFILE_HANDLE User,\r
519 IN UINT8 InfoType,\r
520 OUT EFI_USER_INFO **Info\r
521 )\r
522{\r
523 EFI_STATUS Status;\r
524 EFI_USER_INFO *UserInfo;\r
525 UINTN UserInfoSize;\r
526 EFI_USER_INFO_HANDLE UserInfoHandle;\r
527 EFI_USER_MANAGER_PROTOCOL *UserManager;\r
528 \r
529 //\r
530 // Find user information by information type.\r
531 //\r
532 if (Info == NULL) {\r
533 return EFI_INVALID_PARAMETER;\r
534 }\r
535\r
536 Status = gBS->LocateProtocol (\r
537 &gEfiUserManagerProtocolGuid,\r
538 NULL,\r
539 (VOID **) &UserManager\r
540 );\r
541 if (EFI_ERROR (Status)) {\r
542 return EFI_NOT_FOUND;\r
543 }\r
544\r
545 //\r
546 // Get each user information.\r
547 //\r
548\r
549 UserInfoHandle = NULL;\r
550 UserInfo = NULL;\r
551 UserInfoSize = 0;\r
552 while (TRUE) {\r
553 Status = UserManager->GetNextInfo (UserManager, User, &UserInfoHandle);\r
554 if (EFI_ERROR (Status)) {\r
555 break;\r
556 }\r
557 //\r
558 // Get information.\r
559 //\r
560 Status = UserManager->GetInfo (\r
561 UserManager,\r
562 User,\r
563 UserInfoHandle,\r
564 UserInfo,\r
565 &UserInfoSize\r
566 );\r
567 if (Status == EFI_BUFFER_TOO_SMALL) {\r
568 if (UserInfo != NULL) {\r
569 FreePool (UserInfo);\r
570 }\r
571 UserInfo = AllocateZeroPool (UserInfoSize);\r
572 if (UserInfo == NULL) {\r
573 return EFI_OUT_OF_RESOURCES;\r
574 }\r
575 Status = UserManager->GetInfo (\r
576 UserManager,\r
577 User,\r
578 UserInfoHandle,\r
579 UserInfo,\r
580 &UserInfoSize\r
581 );\r
582 }\r
583 if (EFI_ERROR (Status)) {\r
584 break;\r
585 }\r
586\r
587 ASSERT (UserInfo != NULL);\r
588 if (UserInfo->InfoType == InfoType) {\r
589 *Info = UserInfo;\r
590 return EFI_SUCCESS;\r
591 } \r
592 }\r
593\r
594 if (UserInfo != NULL) {\r
595 FreePool (UserInfo);\r
596 }\r
597 return Status;\r
598}\r
599\r
600\r
601/**\r
602 This function initialize the data mainly used in form browser.\r
603\r
604 @retval EFI_SUCCESS Initialize form data successfully.\r
605 @retval Others Fail to Initialize form data.\r
606\r
607**/\r
608EFI_STATUS\r
609InitFormBrowser (\r
610 VOID\r
611 )\r
612{\r
613 USB_PROVIDER_CALLBACK_INFO *CallbackInfo;\r
614 \r
615 //\r
616 // Initialize driver private data.\r
617 //\r
618 CallbackInfo = AllocateZeroPool (sizeof (USB_PROVIDER_CALLBACK_INFO));\r
619 if (CallbackInfo == NULL) {\r
620 return EFI_OUT_OF_RESOURCES;\r
621 }\r
622 \r
623 CallbackInfo->DriverHandle = NULL;\r
624\r
625 //\r
626 // Publish HII data.\r
627 //\r
628 CallbackInfo->HiiHandle = HiiAddPackages (\r
a0c56a82 629 &gUsbCredentialProviderGuid,\r
0c18794e 630 CallbackInfo->DriverHandle,\r
631 UsbCredentialProviderStrings,\r
632 NULL\r
633 );\r
634 if (CallbackInfo->HiiHandle == NULL) {\r
635 return EFI_OUT_OF_RESOURCES;\r
636 }\r
637 mCallbackInfo = CallbackInfo;\r
638\r
639 return EFI_SUCCESS;\r
640}\r
641\r
642\r
643/**\r
644 Enroll a user on a credential provider.\r
645\r
6f0b8648 646 This function enrolls a user on this credential provider. If the user exists on \r
647 this credential provider, update the user information on this credential provider; \r
648 otherwise add the user information on credential provider.\r
0c18794e 649 \r
6f0b8648 650 @param[in] This Points to this instance of EFI_USER_CREDENTIAL2_PROTOCOL.\r
0c18794e 651 @param[in] User The user profile to enroll.\r
652 \r
653 @retval EFI_SUCCESS User profile was successfully enrolled.\r
654 @retval EFI_ACCESS_DENIED Current user profile does not permit enrollment on the\r
655 user profile handle. Either the user profile cannot enroll\r
656 on any user profile or cannot enroll on a user profile \r
657 other than the current user profile.\r
658 @retval EFI_UNSUPPORTED This credential provider does not support enrollment in\r
659 the pre-OS.\r
660 @retval EFI_DEVICE_ERROR The new credential could not be created because of a device\r
661 error.\r
662 @retval EFI_INVALID_PARAMETER User does not refer to a valid user profile handle.\r
663 \r
664**/\r
665EFI_STATUS\r
666EFIAPI\r
667CredentialEnroll (\r
6f0b8648 668 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r
0c18794e 669 IN EFI_USER_PROFILE_HANDLE User\r
670 )\r
671{\r
672 EFI_STATUS Status;\r
673 UINTN Index;\r
674 USB_INFO UsbInfo;\r
675 EFI_USER_INFO *UserInfo;\r
676 EFI_INPUT_KEY Key;\r
0c18794e 677 UINT8 *UserId;\r
0c18794e 678 CHAR16 *QuestionStr;\r
679 CHAR16 *PromptStr;\r
680\r
681 if ((This == NULL) || (User == NULL)) {\r
682 return EFI_INVALID_PARAMETER;\r
683 }\r
684 \r
0c18794e 685 //\r
686 // Get User Identifier\r
687 //\r
688 UserInfo = NULL;\r
689 Status = FindUserInfoByType (\r
690 User,\r
691 EFI_USER_INFO_IDENTIFIER_RECORD,\r
692 &UserInfo\r
693 );\r
694 if (EFI_ERROR (Status)) {\r
695 return EFI_INVALID_PARAMETER;\r
696 }\r
0c18794e 697\r
6f0b8648 698 CopyMem (UsbInfo.UserId, (UINT8 *) (UserInfo + 1), sizeof (EFI_USER_INFO_IDENTIFIER)); \r
699 FreePool (UserInfo);\r
700 \r
0c18794e 701 //\r
702 // Get Token and User ID to UsbInfo.\r
703 //\r
704 Status = GetToken (UsbInfo.Token);\r
705 if (EFI_ERROR (Status)) {\r
706 QuestionStr = GetStringById (STRING_TOKEN (STR_READ_USB_TOKEN_ERROR));\r
707 PromptStr = GetStringById (STRING_TOKEN (STR_INSERT_USB_TOKEN)); \r
0c18794e 708 CreatePopUp (\r
709 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
710 &Key,\r
711 QuestionStr,\r
712 L"",\r
713 PromptStr,\r
714 NULL\r
715 );\r
0c18794e 716 FreePool (QuestionStr);\r
717 FreePool (PromptStr);\r
0c18794e 718 return Status;\r
719 } \r
0c18794e 720\r
721 //\r
6f0b8648 722 // Check whether User is ever enrolled in the provider.\r
723 // \r
724 for (Index = 0; Index < mUsbTable->Count; Index++) {\r
725 UserId = (UINT8 *) &mUsbTable->UserInfo[Index].UserId;\r
726 if (CompareMem (UserId, (UINT8 *) &UsbInfo.UserId, sizeof (EFI_USER_INFO_IDENTIFIER)) == 0) {\r
727 //\r
728 // User already exists, update the password.\r
729 // \r
730 break;\r
731 }\r
732 }\r
733 \r
734 //\r
735 // Enroll the User to the provider.\r
0c18794e 736 //\r
6f0b8648 737 Status = ModifyTable (Index, &UsbInfo);\r
0c18794e 738 if (EFI_ERROR (Status)) {\r
739 return Status;\r
740 }\r
741\r
0c18794e 742 return EFI_SUCCESS;\r
743}\r
744\r
745\r
746/**\r
747 Returns the user interface information used during user identification.\r
748\r
749 This function returns information about the form used when interacting with the\r
750 user during user identification. The form is the first enabled form in the form-set\r
751 class EFI_HII_USER_CREDENTIAL_FORMSET_GUID installed on the HII handle HiiHandle. If \r
752 the user credential provider does not require a form to identify the user, then this\r
753 function should return EFI_NOT_FOUND.\r
754\r
6f0b8648 755 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
0c18794e 756 @param[out] Hii On return, holds the HII database handle.\r
757 @param[out] FormSetId On return, holds the identifier of the form set which contains\r
758 the form used during user identification.\r
759 @param[out] FormId On return, holds the identifier of the form used during user \r
760 identification.\r
761 \r
762 @retval EFI_SUCCESS Form returned successfully.\r
763 @retval EFI_NOT_FOUND Form not returned.\r
764 @retval EFI_INVALID_PARAMETER Hii is NULL or FormSetId is NULL or FormId is NULL.\r
765 \r
766**/\r
767EFI_STATUS\r
768EFIAPI\r
769CredentialForm (\r
6f0b8648 770 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r
0c18794e 771 OUT EFI_HII_HANDLE *Hii,\r
772 OUT EFI_GUID *FormSetId,\r
773 OUT EFI_FORM_ID *FormId\r
774 )\r
775{\r
776 if ((This == NULL) || (Hii == NULL) || \r
777 (FormSetId == NULL) || (FormId == NULL)) {\r
778 return EFI_INVALID_PARAMETER;\r
779 }\r
780 return EFI_NOT_FOUND;\r
781}\r
782\r
783\r
784/**\r
785 Returns bitmap used to describe the credential provider type.\r
786\r
787 This optional function returns a bitmap which is less than or equal to the number\r
788 of pixels specified by Width and Height. If no such bitmap exists, then EFI_NOT_FOUND\r
789 is returned. \r
790\r
6f0b8648 791 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
0c18794e 792 @param[in, out] Width On entry, points to the desired bitmap width. If NULL then no \r
793 bitmap information will be returned. On exit, points to the \r
794 width of the bitmap returned.\r
795 @param[in, out] Height On entry, points to the desired bitmap height. If NULL then no\r
796 bitmap information will be returned. On exit, points to the \r
797 height of the bitmap returned.\r
798 @param[out] Hii On return, holds the HII database handle. \r
799 @param[out] Image On return, holds the HII image identifier. \r
800 \r
801 @retval EFI_SUCCESS Image identifier returned successfully.\r
802 @retval EFI_NOT_FOUND Image identifier not returned.\r
803 @retval EFI_INVALID_PARAMETER Hii is NULL or Image is NULL.\r
804 \r
805**/\r
806EFI_STATUS\r
807EFIAPI\r
808CredentialTile (\r
6f0b8648 809 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r
0c18794e 810 IN OUT UINTN *Width,\r
811 IN OUT UINTN *Height,\r
812 OUT EFI_HII_HANDLE *Hii,\r
813 OUT EFI_IMAGE_ID *Image\r
814 )\r
815{\r
816 if ((This == NULL) || (Hii == NULL) || (Image == NULL)) {\r
817 return EFI_INVALID_PARAMETER;\r
818 }\r
819 return EFI_NOT_FOUND;\r
820}\r
821\r
822\r
823/**\r
824 Returns string used to describe the credential provider type.\r
825\r
826 This function returns a string which describes the credential provider. If no\r
827 such string exists, then EFI_NOT_FOUND is returned. \r
828\r
6f0b8648 829 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
0c18794e 830 @param[out] Hii On return, holds the HII database handle.\r
831 @param[out] String On return, holds the HII string identifier.\r
832 \r
833 @retval EFI_SUCCESS String identifier returned successfully.\r
834 @retval EFI_NOT_FOUND String identifier not returned.\r
835 @retval EFI_INVALID_PARAMETER Hii is NULL or String is NULL.\r
836 \r
837**/\r
838EFI_STATUS\r
839EFIAPI\r
840CredentialTitle (\r
6f0b8648 841 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r
0c18794e 842 OUT EFI_HII_HANDLE *Hii,\r
843 OUT EFI_STRING_ID *String\r
844 )\r
845{\r
846 if ((This == NULL) || (Hii == NULL) || (String == NULL)) {\r
847 return EFI_INVALID_PARAMETER;\r
848 }\r
849 //\r
850 // Set Hii handle and String ID.\r
851 //\r
852 *Hii = mCallbackInfo->HiiHandle;\r
853 *String = STRING_TOKEN (STR_CREDENTIAL_TITLE);\r
854\r
855 return EFI_SUCCESS;\r
856}\r
857\r
858\r
859/**\r
860 Return the user identifier associated with the currently authenticated user.\r
861\r
862 This function returns the user identifier of the user authenticated by this credential\r
863 provider. This function is called after the credential-related information has been \r
864 submitted on a form OR after a call to Default() has returned that this credential is\r
865 ready to log on.\r
866\r
6f0b8648 867 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
0c18794e 868 @param[in] User The user profile handle of the user profile currently being \r
869 considered by the user identity manager. If NULL, then no user\r
870 profile is currently under consideration.\r
871 @param[out] Identifier On return, points to the user identifier. \r
872 \r
873 @retval EFI_SUCCESS User identifier returned successfully.\r
874 @retval EFI_NOT_READY No user identifier can be returned.\r
875 @retval EFI_ACCESS_DENIED The user has been locked out of this user credential.\r
876 @retval EFI_INVALID_PARAMETER This is NULL, or Identifier is NULL.\r
877 @retval EFI_NOT_FOUND User is not NULL, and the specified user handle can't be\r
878 found in user profile database.\r
879 \r
880**/\r
881EFI_STATUS\r
882EFIAPI\r
883CredentialUser (\r
6f0b8648 884 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r
0c18794e 885 IN EFI_USER_PROFILE_HANDLE User,\r
886 OUT EFI_USER_INFO_IDENTIFIER *Identifier\r
887 )\r
888{\r
889 EFI_STATUS Status;\r
890 UINTN Index;\r
891 EFI_USER_INFO *UserInfo;\r
892 UINT8 *UserId;\r
893 UINT8 *NewUserId;\r
894 UINT8 *UserToken; \r
895 UINT8 ReadToken[HASHED_CREDENTIAL_LEN];\r
896 EFI_INPUT_KEY Key;\r
897 EFI_TPL OldTpl;\r
898 CHAR16 *QuestionStr;\r
899 CHAR16 *PromptStr;\r
900 \r
901 if ((This == NULL) || (Identifier == NULL)) {\r
902 return EFI_INVALID_PARAMETER;\r
903 }\r
904 \r
905 if (User == NULL) {\r
906 //\r
907 // Verify the auto logon user, get user id by matched token.\r
908 //\r
909 if (mUsbTable->Count == 0) {\r
910 return EFI_NOT_READY;\r
911 }\r
912 \r
913 //\r
914 // No user selected, get token first and verify the user existed in user database.\r
915 //\r
916 Status = GetToken (ReadToken);\r
917 if (EFI_ERROR (Status)) {\r
918 return EFI_NOT_READY;\r
919 }\r
920 \r
921 for (Index = 0; Index < mUsbTable->Count; Index++) {\r
922 //\r
923 // find the specified credential in the Usb credential database.\r
924 //\r
925 UserToken = mUsbTable->UserInfo[Index].Token;\r
926 if (CompareMem (UserToken, ReadToken, HASHED_CREDENTIAL_LEN) == 0) {\r
927 UserId = (UINT8 *) &mUsbTable->UserInfo[Index].UserId;\r
928 CopyMem (Identifier, UserId, sizeof (EFI_USER_INFO_IDENTIFIER));\r
929 return EFI_SUCCESS;\r
930 }\r
931 }\r
932\r
933 return EFI_NOT_READY; \r
934 }\r
935 \r
936 // \r
937 // User is not NULL here. Read a token, and check whether the token matches with \r
938 // the selected user's Token. If not, try to find a token in token DB to matches \r
939 // with read token.\r
940 // \r
941 \r
942 Status = GetToken (ReadToken);\r
943 if (EFI_ERROR (Status)) {\r
944 QuestionStr = GetStringById (STRING_TOKEN (STR_READ_USB_TOKEN_ERROR));\r
945 PromptStr = GetStringById (STRING_TOKEN (STR_INSERT_USB_TOKEN));\r
946 OldTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
947 gBS->RestoreTPL (TPL_APPLICATION);\r
948 CreatePopUp (\r
949 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
950 &Key,\r
951 QuestionStr,\r
952 L"",\r
953 PromptStr,\r
954 NULL\r
955 );\r
956 gBS->RaiseTPL (OldTpl);\r
957 FreePool (QuestionStr);\r
958 FreePool (PromptStr);\r
959 return EFI_NOT_FOUND;\r
960 }\r
961\r
962 //\r
963 // Get the selected user's identifier.\r
964 //\r
965 Status = FindUserInfoByType (User, EFI_USER_INFO_IDENTIFIER_RECORD, &UserInfo);\r
966 if (EFI_ERROR (Status)) {\r
967 return EFI_NOT_FOUND;\r
968 } \r
969 \r
970 //\r
971 // Check the selected user's Token with the read token.\r
972 //\r
973 for (Index = 0; Index < mUsbTable->Count; Index++) {\r
974 UserId = (UINT8 *) &mUsbTable->UserInfo[Index].UserId;\r
975 NewUserId = (UINT8 *) (UserInfo + 1);\r
976 if (CompareMem (UserId, NewUserId, sizeof (EFI_USER_INFO_IDENTIFIER)) == 0) {\r
977 //\r
978 // The user's ID is found in the UsbTable.\r
979 //\r
980 UserToken = mUsbTable->UserInfo[Index].Token;\r
981 if (CompareMem (UserToken, ReadToken, HASHED_CREDENTIAL_LEN) == 0) {\r
982 //\r
983 // The read token matches with the one in UsbTable.\r
984 //\r
985 CopyMem (Identifier, UserId, sizeof (EFI_USER_INFO_IDENTIFIER));\r
986 FreePool (UserInfo);\r
987 return EFI_SUCCESS;\r
988 } \r
989 }\r
990 }\r
ae4cb94f 991\r
992 FreePool (UserInfo); \r
993 \r
994 return EFI_NOT_READY;\r
0c18794e 995}\r
996\r
997\r
998/**\r
999 Indicate that user interface interaction has begun for the specified credential.\r
1000\r
1001 This function is called when a credential provider is selected by the user. If \r
1002 AutoLogon returns FALSE, then the user interface will be constructed by the User\r
1003 Identity Manager. \r
1004\r
6f0b8648 1005 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
0c18794e 1006 @param[out] AutoLogon On return, points to the credential provider's capabilities \r
1007 after the credential provider has been selected by the user. \r
1008 \r
1009 @retval EFI_SUCCESS Credential provider successfully selected.\r
1010 @retval EFI_INVALID_PARAMETER AutoLogon is NULL.\r
1011 \r
1012**/\r
1013EFI_STATUS\r
1014EFIAPI\r
1015CredentialSelect (\r
6f0b8648 1016 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r
0c18794e 1017 OUT EFI_CREDENTIAL_LOGON_FLAGS *AutoLogon\r
1018 )\r
1019{\r
1020 if ((This == NULL) || (AutoLogon == NULL)) {\r
1021 return EFI_INVALID_PARAMETER;\r
1022 }\r
1023\r
1024 *AutoLogon = EFI_CREDENTIAL_LOGON_FLAG_DEFAULT | EFI_CREDENTIAL_LOGON_FLAG_AUTO;\r
1025\r
1026 return EFI_SUCCESS;\r
1027}\r
1028\r
1029\r
1030/**\r
1031 Indicate that user interface interaction has ended for the specified credential.\r
1032\r
1033 This function is called when a credential provider is deselected by the user.\r
1034\r
6f0b8648 1035 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
0c18794e 1036 \r
1037 @retval EFI_SUCCESS Credential provider successfully deselected.\r
1038 \r
1039**/\r
1040EFI_STATUS\r
1041EFIAPI\r
1042CredentialDeselect (\r
6f0b8648 1043 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This\r
0c18794e 1044 )\r
1045{\r
1046 if (This == NULL) {\r
1047 return EFI_INVALID_PARAMETER;\r
1048 }\r
1049 return EFI_SUCCESS;\r
1050}\r
1051\r
1052\r
1053/**\r
1054 Return the default logon behavior for this user credential.\r
1055\r
1056 This function reports the default login behavior regarding this credential provider. \r
1057\r
6f0b8648 1058 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
0c18794e 1059 @param[out] AutoLogon On return, holds whether the credential provider should be used\r
1060 by default to automatically log on the user. \r
1061 \r
1062 @retval EFI_SUCCESS Default information successfully returned.\r
1063 @retval EFI_INVALID_PARAMETER AutoLogon is NULL.\r
1064 \r
1065**/\r
1066EFI_STATUS\r
1067EFIAPI\r
1068CredentialDefault (\r
6f0b8648 1069 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r
0c18794e 1070 OUT EFI_CREDENTIAL_LOGON_FLAGS *AutoLogon\r
1071 )\r
1072{\r
1073 if ((This == NULL) || (AutoLogon == NULL)) {\r
1074 return EFI_INVALID_PARAMETER;\r
1075 }\r
1076\r
1077 *AutoLogon = EFI_CREDENTIAL_LOGON_FLAG_DEFAULT | EFI_CREDENTIAL_LOGON_FLAG_AUTO;\r
1078 return EFI_SUCCESS;\r
1079}\r
1080\r
1081\r
1082/**\r
1083 Return information attached to the credential provider.\r
1084\r
1085 This function returns user information. \r
1086\r
6f0b8648 1087 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
0c18794e 1088 @param[in] UserInfo Handle of the user information data record. \r
1089 @param[out] Info On entry, points to a buffer of at least *InfoSize bytes. On\r
1090 exit, holds the user information. If the buffer is too small\r
1091 to hold the information, then EFI_BUFFER_TOO_SMALL is returned\r
1092 and InfoSize is updated to contain the number of bytes actually\r
1093 required.\r
1094 @param[in, out] InfoSize On entry, points to the size of Info. On return, points to the \r
1095 size of the user information. \r
1096 \r
1097 @retval EFI_SUCCESS Information returned successfully.\r
1098 @retval EFI_BUFFER_TOO_SMALL The size specified by InfoSize is too small to hold all of the\r
1099 user information. The size required is returned in *InfoSize.\r
1100 @retval EFI_INVALID_PARAMETER Info is NULL or InfoSize is NULL.\r
1101 @retval EFI_NOT_FOUND The specified UserInfo does not refer to a valid user info handle. \r
1102 \r
1103**/\r
1104EFI_STATUS\r
1105EFIAPI\r
1106CredentialGetInfo (\r
6f0b8648 1107 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r
0c18794e 1108 IN EFI_USER_INFO_HANDLE UserInfo,\r
1109 OUT EFI_USER_INFO *Info,\r
1110 IN OUT UINTN *InfoSize\r
1111 )\r
1112{\r
1113 EFI_USER_INFO *CredentialInfo;\r
1114 UINTN Index;\r
1115 \r
1116 if ((This == NULL) || (InfoSize == NULL) || (Info == NULL)) {\r
1117 return EFI_INVALID_PARAMETER;\r
1118 }\r
1119\r
1120 if ((UserInfo == NULL) || (mUsbInfoHandle == NULL)) {\r
1121 return EFI_NOT_FOUND;\r
1122 }\r
1123 \r
1124 //\r
1125 // Find information handle in credential info table.\r
1126 //\r
1127 for (Index = 0; Index < mUsbInfoHandle->Count; Index++) {\r
1128 CredentialInfo = mUsbInfoHandle->Info[Index];\r
1129 if (UserInfo == (EFI_USER_INFO_HANDLE)CredentialInfo) {\r
1130 //\r
1131 // The handle is found, copy the user info.\r
1132 //\r
1133 if (CredentialInfo->InfoSize > *InfoSize) {\r
1134 *InfoSize = CredentialInfo->InfoSize;\r
1135 return EFI_BUFFER_TOO_SMALL;\r
1136 }\r
1137 \r
1138 CopyMem (Info, CredentialInfo, CredentialInfo->InfoSize); \r
1139 return EFI_SUCCESS; \r
1140 }\r
1141 }\r
1142 \r
1143 return EFI_NOT_FOUND;\r
1144}\r
1145\r
1146\r
1147/**\r
1148 Enumerate all of the user informations on the credential provider.\r
1149\r
1150 This function returns the next user information record. To retrieve the first user\r
1151 information record handle, point UserInfo at a NULL. Each subsequent call will retrieve\r
1152 another user information record handle until there are no more, at which point UserInfo\r
1153 will point to NULL. \r
1154\r
6f0b8648 1155 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
0c18794e 1156 @param[in, out] UserInfo On entry, points to the previous user information handle or NULL\r
1157 to start enumeration. On exit, points to the next user information\r
1158 handle or NULL if there is no more user information.\r
1159 \r
1160 @retval EFI_SUCCESS User information returned.\r
1161 @retval EFI_NOT_FOUND No more user information found.\r
1162 @retval EFI_INVALID_PARAMETER UserInfo is NULL.\r
1163 \r
1164**/\r
1165EFI_STATUS\r
1166EFIAPI\r
1167CredentialGetNextInfo (\r
6f0b8648 1168 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r
0c18794e 1169 IN OUT EFI_USER_INFO_HANDLE *UserInfo\r
1170 )\r
1171{\r
1172 EFI_USER_INFO *Info;\r
1173 CHAR16 *ProvNameStr;\r
1174 UINTN InfoLen;\r
1175 UINTN Index;\r
1176 UINTN ProvStrLen;\r
1177 \r
1178 if ((This == NULL) || (UserInfo == NULL)) {\r
1179 return EFI_INVALID_PARAMETER;\r
1180 }\r
1181\r
1182 if (mUsbInfoHandle == NULL) {\r
1183 //\r
1184 // Initilized user info table. There are 4 user info records in the table.\r
1185 //\r
1186 InfoLen = sizeof (USB_CREDENTIAL_INFO) + (4 - 1) * sizeof (EFI_USER_INFO *);\r
1187 mUsbInfoHandle = AllocateZeroPool (InfoLen);\r
1188 if (mUsbInfoHandle == NULL) {\r
1189 *UserInfo = NULL;\r
1190 return EFI_NOT_FOUND;\r
1191 }\r
1192\r
1193 //\r
1194 // The first information, Credential Provider info.\r
1195 //\r
1196 InfoLen = sizeof (EFI_USER_INFO) + sizeof (EFI_GUID);\r
1197 Info = AllocateZeroPool (InfoLen);\r
1198 ASSERT (Info != NULL);\r
1199 \r
1200 Info->InfoType = EFI_USER_INFO_CREDENTIAL_PROVIDER_RECORD;\r
1201 Info->InfoSize = (UINT32) InfoLen;\r
1202 Info->InfoAttribs = EFI_USER_INFO_PROTECTED;\r
a0c56a82
LG
1203 CopyGuid (&Info->Credential, &gUsbCredentialProviderGuid);\r
1204 CopyGuid ((EFI_GUID *)(Info + 1), &gUsbCredentialProviderGuid);\r
0c18794e 1205 \r
1206 mUsbInfoHandle->Info[0] = Info;\r
1207 mUsbInfoHandle->Count++;\r
1208\r
1209 //\r
1210 // The second information, Credential Provider name info.\r
1211 //\r
1212 ProvNameStr = GetStringById (STRING_TOKEN (STR_PROVIDER_NAME));\r
1213 ProvStrLen = StrSize (ProvNameStr);\r
1214 InfoLen = sizeof (EFI_USER_INFO) + ProvStrLen;\r
1215 Info = AllocateZeroPool (InfoLen);\r
1216 ASSERT (Info != NULL);\r
1217 \r
1218 Info->InfoType = EFI_USER_INFO_CREDENTIAL_PROVIDER_NAME_RECORD;\r
1219 Info->InfoSize = (UINT32) InfoLen;\r
1220 Info->InfoAttribs = EFI_USER_INFO_PROTECTED;\r
a0c56a82 1221 CopyGuid (&Info->Credential, &gUsbCredentialProviderGuid);\r
0c18794e 1222 CopyMem ((UINT8*)(Info + 1), ProvNameStr, ProvStrLen);\r
1223 FreePool (ProvNameStr);\r
1224 \r
1225 mUsbInfoHandle->Info[1] = Info;\r
1226 mUsbInfoHandle->Count++;\r
1227\r
1228 //\r
1229 // The third information, Credential Provider type info.\r
1230 //\r
1231 InfoLen = sizeof (EFI_USER_INFO) + sizeof (EFI_GUID);\r
1232 Info = AllocateZeroPool (InfoLen);\r
1233 ASSERT (Info != NULL);\r
1234 \r
1235 Info->InfoType = EFI_USER_INFO_CREDENTIAL_TYPE_RECORD;\r
1236 Info->InfoSize = (UINT32) InfoLen;\r
1237 Info->InfoAttribs = EFI_USER_INFO_PROTECTED;\r
a0c56a82 1238 CopyGuid (&Info->Credential, &gUsbCredentialProviderGuid);\r
0c18794e 1239 CopyGuid ((EFI_GUID *)(Info + 1), &gEfiUserCredentialClassSecureCardGuid);\r
1240 \r
1241 mUsbInfoHandle->Info[2] = Info;\r
1242 mUsbInfoHandle->Count++;\r
1243 \r
1244 //\r
1245 // The fourth information, Credential Provider type name info.\r
1246 //\r
1247 ProvNameStr = GetStringById (STRING_TOKEN (STR_PROVIDER_TYPE_NAME));\r
1248 ProvStrLen = StrSize (ProvNameStr);\r
1249 InfoLen = sizeof (EFI_USER_INFO) + ProvStrLen;\r
1250 Info = AllocateZeroPool (InfoLen);\r
1251 ASSERT (Info != NULL);\r
1252 \r
1253 Info->InfoType = EFI_USER_INFO_CREDENTIAL_PROVIDER_NAME_RECORD;\r
1254 Info->InfoSize = (UINT32) InfoLen;\r
1255 Info->InfoAttribs = EFI_USER_INFO_PROTECTED;\r
a0c56a82 1256 CopyGuid (&Info->Credential, &gUsbCredentialProviderGuid);\r
0c18794e 1257 CopyMem ((UINT8*)(Info + 1), ProvNameStr, ProvStrLen);\r
1258 FreePool (ProvNameStr);\r
1259 \r
1260 mUsbInfoHandle->Info[3] = Info;\r
1261 mUsbInfoHandle->Count++;\r
1262 }\r
1263 \r
1264 if (*UserInfo == NULL) {\r
1265 //\r
1266 // Return the first info handle.\r
1267 //\r
1268 *UserInfo = (EFI_USER_INFO_HANDLE) mUsbInfoHandle->Info[0];\r
1269 return EFI_SUCCESS;\r
1270 }\r
1271 \r
1272 //\r
1273 // Find information handle in credential info table.\r
1274 //\r
1275 for (Index = 0; Index < mUsbInfoHandle->Count; Index++) {\r
1276 Info = mUsbInfoHandle->Info[Index];\r
1277 if (*UserInfo == (EFI_USER_INFO_HANDLE)Info) {\r
1278 //\r
1279 // The handle is found, get the next one.\r
1280 //\r
1281 if (Index == mUsbInfoHandle->Count - 1) {\r
1282 //\r
1283 // Already last one.\r
1284 //\r
1285 *UserInfo = NULL;\r
1286 return EFI_NOT_FOUND;\r
1287 }\r
1288 Index++;\r
1289 *UserInfo = (EFI_USER_INFO_HANDLE)mUsbInfoHandle->Info[Index];\r
1290 return EFI_SUCCESS; \r
1291 }\r
1292 }\r
1293\r
1294 *UserInfo = NULL;\r
1295 return EFI_NOT_FOUND;\r
1296}\r
1297\r
1298\r
6f0b8648 1299/**\r
1300 Delete a user on this credential provider.\r
1301\r
1302 This function deletes a user on this credential provider. \r
1303\r
1304 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
1305 @param[in] User The user profile handle to delete.\r
1306\r
1307 @retval EFI_SUCCESS User profile was successfully deleted.\r
1308 @retval EFI_ACCESS_DENIED Current user profile does not permit deletion on the user profile handle. \r
1309 Either the user profile cannot delete on any user profile or cannot delete \r
1310 on a user profile other than the current user profile. \r
1311 @retval EFI_UNSUPPORTED This credential provider does not support deletion in the pre-OS.\r
1312 @retval EFI_DEVICE_ERROR The new credential could not be deleted because of a device error.\r
1313 @retval EFI_INVALID_PARAMETER User does not refer to a valid user profile handle.\r
1314**/\r
1315EFI_STATUS\r
1316EFIAPI\r
1317CredentialDelete (\r
1318 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r
1319 IN EFI_USER_PROFILE_HANDLE User\r
1320 )\r
1321{\r
1322 EFI_STATUS Status;\r
1323 EFI_USER_INFO *UserInfo;\r
1324 UINT8 *UserId;\r
1325 UINT8 *NewUserId;\r
1326 UINTN Index;\r
1327 \r
1328 if ((This == NULL) || (User == NULL)) {\r
1329 return EFI_INVALID_PARAMETER;\r
1330 }\r
1331\r
1332 //\r
1333 // Get User Identifier.\r
1334 //\r
1335 UserInfo = NULL;\r
1336 Status = FindUserInfoByType (\r
1337 User,\r
1338 EFI_USER_INFO_IDENTIFIER_RECORD,\r
1339 &UserInfo\r
1340 );\r
1341 if (EFI_ERROR (Status)) {\r
1342 return EFI_INVALID_PARAMETER;\r
1343 }\r
1344\r
1345 //\r
1346 // Find the user by user identifier in mPwdTable.\r
1347 // \r
1348 for (Index = 0; Index < mUsbTable->Count; Index++) {\r
1349 UserId = (UINT8 *) &mUsbTable->UserInfo[Index].UserId;\r
1350 NewUserId = (UINT8 *) (UserInfo + 1);\r
1351 if (CompareMem (UserId, NewUserId, sizeof (EFI_USER_INFO_IDENTIFIER)) == 0) {\r
1352 //\r
1353 // Found the user, delete it.\r
1354 //\r
1355 ModifyTable (Index, NULL);\r
1356 break;\r
1357 }\r
1358 }\r
1359\r
1360 FreePool (UserInfo);\r
1361 return EFI_SUCCESS;\r
1362}\r
1363\r
1364\r
0c18794e 1365/**\r
1366 Main entry for this driver.\r
1367\r
1368 @param ImageHandle Image handle this driver.\r
1369 @param SystemTable Pointer to SystemTable.\r
1370\r
1371 @retval EFI_SUCESS This function always complete successfully.\r
1372\r
1373**/\r
1374EFI_STATUS\r
1375EFIAPI\r
1376UsbProviderInit (\r
1377 IN EFI_HANDLE ImageHandle,\r
1378 IN EFI_SYSTEM_TABLE *SystemTable\r
1379 )\r
1380{\r
1381 EFI_STATUS Status;\r
1382\r
1383 //\r
1384 // Init credential table.\r
1385 //\r
1386 Status = InitCredentialTable ();\r
1387 if (EFI_ERROR (Status)) {\r
1388 return Status;\r
1389 }\r
1390 \r
1391 //\r
1392 // Init Form Browser\r
1393 //\r
1394 Status = InitFormBrowser ();\r
1395 if (EFI_ERROR (Status)) {\r
1396 return Status;\r
1397 }\r
1398 \r
1399 //\r
1400 // Install protocol interfaces for the Usb Credential Provider.\r
1401 //\r
1402 Status = gBS->InstallProtocolInterface (\r
1403 &mCallbackInfo->DriverHandle,\r
6f0b8648 1404 &gEfiUserCredential2ProtocolGuid,\r
0c18794e 1405 EFI_NATIVE_INTERFACE,\r
1406 &gUsbCredentialProviderDriver\r
1407 );\r
1408 return Status;\r
1409}\r