Force UID modules build error to warn user that currently it is just a sample.
[mirror_edk2.git] / SecurityPkg / UserIdentification / UsbCredentialProviderDxe / UsbCredentialProvider.c
CommitLineData
0c18794e 1/** @file\r
2 Usb Credential Provider driver implemenetation.\r
3 \r
68d151bb 4Copyright (c) 2009 - 2014, 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
0c18794e 897 CHAR16 *QuestionStr;\r
898 CHAR16 *PromptStr;\r
899 \r
900 if ((This == NULL) || (Identifier == NULL)) {\r
901 return EFI_INVALID_PARAMETER;\r
902 }\r
903 \r
904 if (User == NULL) {\r
905 //\r
906 // Verify the auto logon user, get user id by matched token.\r
907 //\r
908 if (mUsbTable->Count == 0) {\r
909 return EFI_NOT_READY;\r
910 }\r
911 \r
912 //\r
913 // No user selected, get token first and verify the user existed in user database.\r
914 //\r
915 Status = GetToken (ReadToken);\r
916 if (EFI_ERROR (Status)) {\r
917 return EFI_NOT_READY;\r
918 }\r
919 \r
920 for (Index = 0; Index < mUsbTable->Count; Index++) {\r
921 //\r
922 // find the specified credential in the Usb credential database.\r
923 //\r
924 UserToken = mUsbTable->UserInfo[Index].Token;\r
925 if (CompareMem (UserToken, ReadToken, HASHED_CREDENTIAL_LEN) == 0) {\r
926 UserId = (UINT8 *) &mUsbTable->UserInfo[Index].UserId;\r
927 CopyMem (Identifier, UserId, sizeof (EFI_USER_INFO_IDENTIFIER));\r
928 return EFI_SUCCESS;\r
929 }\r
930 }\r
931\r
932 return EFI_NOT_READY; \r
933 }\r
934 \r
935 // \r
936 // User is not NULL here. Read a token, and check whether the token matches with \r
937 // the selected user's Token. If not, try to find a token in token DB to matches \r
938 // with read token.\r
939 // \r
940 \r
941 Status = GetToken (ReadToken);\r
942 if (EFI_ERROR (Status)) {\r
943 QuestionStr = GetStringById (STRING_TOKEN (STR_READ_USB_TOKEN_ERROR));\r
944 PromptStr = GetStringById (STRING_TOKEN (STR_INSERT_USB_TOKEN));\r
0c18794e 945 CreatePopUp (\r
946 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
947 &Key,\r
948 QuestionStr,\r
949 L"",\r
950 PromptStr,\r
951 NULL\r
952 );\r
0c18794e 953 FreePool (QuestionStr);\r
954 FreePool (PromptStr);\r
955 return EFI_NOT_FOUND;\r
956 }\r
957\r
958 //\r
959 // Get the selected user's identifier.\r
960 //\r
961 Status = FindUserInfoByType (User, EFI_USER_INFO_IDENTIFIER_RECORD, &UserInfo);\r
962 if (EFI_ERROR (Status)) {\r
963 return EFI_NOT_FOUND;\r
964 } \r
965 \r
966 //\r
967 // Check the selected user's Token with the read token.\r
968 //\r
969 for (Index = 0; Index < mUsbTable->Count; Index++) {\r
970 UserId = (UINT8 *) &mUsbTable->UserInfo[Index].UserId;\r
971 NewUserId = (UINT8 *) (UserInfo + 1);\r
972 if (CompareMem (UserId, NewUserId, sizeof (EFI_USER_INFO_IDENTIFIER)) == 0) {\r
973 //\r
974 // The user's ID is found in the UsbTable.\r
975 //\r
976 UserToken = mUsbTable->UserInfo[Index].Token;\r
977 if (CompareMem (UserToken, ReadToken, HASHED_CREDENTIAL_LEN) == 0) {\r
978 //\r
979 // The read token matches with the one in UsbTable.\r
980 //\r
981 CopyMem (Identifier, UserId, sizeof (EFI_USER_INFO_IDENTIFIER));\r
982 FreePool (UserInfo);\r
983 return EFI_SUCCESS;\r
984 } \r
985 }\r
986 }\r
ae4cb94f 987\r
988 FreePool (UserInfo); \r
989 \r
990 return EFI_NOT_READY;\r
0c18794e 991}\r
992\r
993\r
994/**\r
995 Indicate that user interface interaction has begun for the specified credential.\r
996\r
997 This function is called when a credential provider is selected by the user. If \r
998 AutoLogon returns FALSE, then the user interface will be constructed by the User\r
999 Identity Manager. \r
1000\r
6f0b8648 1001 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
0c18794e 1002 @param[out] AutoLogon On return, points to the credential provider's capabilities \r
1003 after the credential provider has been selected by the user. \r
1004 \r
1005 @retval EFI_SUCCESS Credential provider successfully selected.\r
1006 @retval EFI_INVALID_PARAMETER AutoLogon is NULL.\r
1007 \r
1008**/\r
1009EFI_STATUS\r
1010EFIAPI\r
1011CredentialSelect (\r
6f0b8648 1012 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r
0c18794e 1013 OUT EFI_CREDENTIAL_LOGON_FLAGS *AutoLogon\r
1014 )\r
1015{\r
1016 if ((This == NULL) || (AutoLogon == NULL)) {\r
1017 return EFI_INVALID_PARAMETER;\r
1018 }\r
1019\r
1020 *AutoLogon = EFI_CREDENTIAL_LOGON_FLAG_DEFAULT | EFI_CREDENTIAL_LOGON_FLAG_AUTO;\r
1021\r
1022 return EFI_SUCCESS;\r
1023}\r
1024\r
1025\r
1026/**\r
1027 Indicate that user interface interaction has ended for the specified credential.\r
1028\r
1029 This function is called when a credential provider is deselected by the user.\r
1030\r
6f0b8648 1031 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
0c18794e 1032 \r
1033 @retval EFI_SUCCESS Credential provider successfully deselected.\r
1034 \r
1035**/\r
1036EFI_STATUS\r
1037EFIAPI\r
1038CredentialDeselect (\r
6f0b8648 1039 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This\r
0c18794e 1040 )\r
1041{\r
1042 if (This == NULL) {\r
1043 return EFI_INVALID_PARAMETER;\r
1044 }\r
1045 return EFI_SUCCESS;\r
1046}\r
1047\r
1048\r
1049/**\r
1050 Return the default logon behavior for this user credential.\r
1051\r
1052 This function reports the default login behavior regarding this credential provider. \r
1053\r
6f0b8648 1054 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
0c18794e 1055 @param[out] AutoLogon On return, holds whether the credential provider should be used\r
1056 by default to automatically log on the user. \r
1057 \r
1058 @retval EFI_SUCCESS Default information successfully returned.\r
1059 @retval EFI_INVALID_PARAMETER AutoLogon is NULL.\r
1060 \r
1061**/\r
1062EFI_STATUS\r
1063EFIAPI\r
1064CredentialDefault (\r
6f0b8648 1065 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r
0c18794e 1066 OUT EFI_CREDENTIAL_LOGON_FLAGS *AutoLogon\r
1067 )\r
1068{\r
1069 if ((This == NULL) || (AutoLogon == NULL)) {\r
1070 return EFI_INVALID_PARAMETER;\r
1071 }\r
1072\r
1073 *AutoLogon = EFI_CREDENTIAL_LOGON_FLAG_DEFAULT | EFI_CREDENTIAL_LOGON_FLAG_AUTO;\r
1074 return EFI_SUCCESS;\r
1075}\r
1076\r
1077\r
1078/**\r
1079 Return information attached to the credential provider.\r
1080\r
1081 This function returns user information. \r
1082\r
6f0b8648 1083 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
0c18794e 1084 @param[in] UserInfo Handle of the user information data record. \r
1085 @param[out] Info On entry, points to a buffer of at least *InfoSize bytes. On\r
1086 exit, holds the user information. If the buffer is too small\r
1087 to hold the information, then EFI_BUFFER_TOO_SMALL is returned\r
1088 and InfoSize is updated to contain the number of bytes actually\r
1089 required.\r
1090 @param[in, out] InfoSize On entry, points to the size of Info. On return, points to the \r
1091 size of the user information. \r
1092 \r
1093 @retval EFI_SUCCESS Information returned successfully.\r
1094 @retval EFI_BUFFER_TOO_SMALL The size specified by InfoSize is too small to hold all of the\r
1095 user information. The size required is returned in *InfoSize.\r
1096 @retval EFI_INVALID_PARAMETER Info is NULL or InfoSize is NULL.\r
1097 @retval EFI_NOT_FOUND The specified UserInfo does not refer to a valid user info handle. \r
1098 \r
1099**/\r
1100EFI_STATUS\r
1101EFIAPI\r
1102CredentialGetInfo (\r
6f0b8648 1103 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r
0c18794e 1104 IN EFI_USER_INFO_HANDLE UserInfo,\r
1105 OUT EFI_USER_INFO *Info,\r
1106 IN OUT UINTN *InfoSize\r
1107 )\r
1108{\r
1109 EFI_USER_INFO *CredentialInfo;\r
1110 UINTN Index;\r
1111 \r
1112 if ((This == NULL) || (InfoSize == NULL) || (Info == NULL)) {\r
1113 return EFI_INVALID_PARAMETER;\r
1114 }\r
1115\r
1116 if ((UserInfo == NULL) || (mUsbInfoHandle == NULL)) {\r
1117 return EFI_NOT_FOUND;\r
1118 }\r
1119 \r
1120 //\r
1121 // Find information handle in credential info table.\r
1122 //\r
1123 for (Index = 0; Index < mUsbInfoHandle->Count; Index++) {\r
1124 CredentialInfo = mUsbInfoHandle->Info[Index];\r
1125 if (UserInfo == (EFI_USER_INFO_HANDLE)CredentialInfo) {\r
1126 //\r
1127 // The handle is found, copy the user info.\r
1128 //\r
1129 if (CredentialInfo->InfoSize > *InfoSize) {\r
1130 *InfoSize = CredentialInfo->InfoSize;\r
1131 return EFI_BUFFER_TOO_SMALL;\r
1132 }\r
1133 \r
1134 CopyMem (Info, CredentialInfo, CredentialInfo->InfoSize); \r
1135 return EFI_SUCCESS; \r
1136 }\r
1137 }\r
1138 \r
1139 return EFI_NOT_FOUND;\r
1140}\r
1141\r
1142\r
1143/**\r
1144 Enumerate all of the user informations on the credential provider.\r
1145\r
1146 This function returns the next user information record. To retrieve the first user\r
1147 information record handle, point UserInfo at a NULL. Each subsequent call will retrieve\r
1148 another user information record handle until there are no more, at which point UserInfo\r
1149 will point to NULL. \r
1150\r
6f0b8648 1151 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
0c18794e 1152 @param[in, out] UserInfo On entry, points to the previous user information handle or NULL\r
1153 to start enumeration. On exit, points to the next user information\r
1154 handle or NULL if there is no more user information.\r
1155 \r
1156 @retval EFI_SUCCESS User information returned.\r
1157 @retval EFI_NOT_FOUND No more user information found.\r
1158 @retval EFI_INVALID_PARAMETER UserInfo is NULL.\r
1159 \r
1160**/\r
1161EFI_STATUS\r
1162EFIAPI\r
1163CredentialGetNextInfo (\r
6f0b8648 1164 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r
0c18794e 1165 IN OUT EFI_USER_INFO_HANDLE *UserInfo\r
1166 )\r
1167{\r
1168 EFI_USER_INFO *Info;\r
1169 CHAR16 *ProvNameStr;\r
1170 UINTN InfoLen;\r
1171 UINTN Index;\r
1172 UINTN ProvStrLen;\r
1173 \r
1174 if ((This == NULL) || (UserInfo == NULL)) {\r
1175 return EFI_INVALID_PARAMETER;\r
1176 }\r
1177\r
1178 if (mUsbInfoHandle == NULL) {\r
1179 //\r
1180 // Initilized user info table. There are 4 user info records in the table.\r
1181 //\r
1182 InfoLen = sizeof (USB_CREDENTIAL_INFO) + (4 - 1) * sizeof (EFI_USER_INFO *);\r
1183 mUsbInfoHandle = AllocateZeroPool (InfoLen);\r
1184 if (mUsbInfoHandle == NULL) {\r
1185 *UserInfo = NULL;\r
1186 return EFI_NOT_FOUND;\r
1187 }\r
1188\r
1189 //\r
1190 // The first information, Credential Provider info.\r
1191 //\r
1192 InfoLen = sizeof (EFI_USER_INFO) + sizeof (EFI_GUID);\r
1193 Info = AllocateZeroPool (InfoLen);\r
1194 ASSERT (Info != NULL);\r
1195 \r
1196 Info->InfoType = EFI_USER_INFO_CREDENTIAL_PROVIDER_RECORD;\r
1197 Info->InfoSize = (UINT32) InfoLen;\r
1198 Info->InfoAttribs = EFI_USER_INFO_PROTECTED;\r
a0c56a82
LG
1199 CopyGuid (&Info->Credential, &gUsbCredentialProviderGuid);\r
1200 CopyGuid ((EFI_GUID *)(Info + 1), &gUsbCredentialProviderGuid);\r
0c18794e 1201 \r
1202 mUsbInfoHandle->Info[0] = Info;\r
1203 mUsbInfoHandle->Count++;\r
1204\r
1205 //\r
1206 // The second information, Credential Provider name info.\r
1207 //\r
1208 ProvNameStr = GetStringById (STRING_TOKEN (STR_PROVIDER_NAME));\r
1209 ProvStrLen = StrSize (ProvNameStr);\r
1210 InfoLen = sizeof (EFI_USER_INFO) + ProvStrLen;\r
1211 Info = AllocateZeroPool (InfoLen);\r
1212 ASSERT (Info != NULL);\r
1213 \r
1214 Info->InfoType = EFI_USER_INFO_CREDENTIAL_PROVIDER_NAME_RECORD;\r
1215 Info->InfoSize = (UINT32) InfoLen;\r
1216 Info->InfoAttribs = EFI_USER_INFO_PROTECTED;\r
a0c56a82 1217 CopyGuid (&Info->Credential, &gUsbCredentialProviderGuid);\r
0c18794e 1218 CopyMem ((UINT8*)(Info + 1), ProvNameStr, ProvStrLen);\r
1219 FreePool (ProvNameStr);\r
1220 \r
1221 mUsbInfoHandle->Info[1] = Info;\r
1222 mUsbInfoHandle->Count++;\r
1223\r
1224 //\r
1225 // The third information, Credential Provider type info.\r
1226 //\r
1227 InfoLen = sizeof (EFI_USER_INFO) + sizeof (EFI_GUID);\r
1228 Info = AllocateZeroPool (InfoLen);\r
1229 ASSERT (Info != NULL);\r
1230 \r
1231 Info->InfoType = EFI_USER_INFO_CREDENTIAL_TYPE_RECORD;\r
1232 Info->InfoSize = (UINT32) InfoLen;\r
1233 Info->InfoAttribs = EFI_USER_INFO_PROTECTED;\r
a0c56a82 1234 CopyGuid (&Info->Credential, &gUsbCredentialProviderGuid);\r
0c18794e 1235 CopyGuid ((EFI_GUID *)(Info + 1), &gEfiUserCredentialClassSecureCardGuid);\r
1236 \r
1237 mUsbInfoHandle->Info[2] = Info;\r
1238 mUsbInfoHandle->Count++;\r
1239 \r
1240 //\r
1241 // The fourth information, Credential Provider type name info.\r
1242 //\r
1243 ProvNameStr = GetStringById (STRING_TOKEN (STR_PROVIDER_TYPE_NAME));\r
1244 ProvStrLen = StrSize (ProvNameStr);\r
1245 InfoLen = sizeof (EFI_USER_INFO) + ProvStrLen;\r
1246 Info = AllocateZeroPool (InfoLen);\r
1247 ASSERT (Info != NULL);\r
1248 \r
1249 Info->InfoType = EFI_USER_INFO_CREDENTIAL_PROVIDER_NAME_RECORD;\r
1250 Info->InfoSize = (UINT32) InfoLen;\r
1251 Info->InfoAttribs = EFI_USER_INFO_PROTECTED;\r
a0c56a82 1252 CopyGuid (&Info->Credential, &gUsbCredentialProviderGuid);\r
0c18794e 1253 CopyMem ((UINT8*)(Info + 1), ProvNameStr, ProvStrLen);\r
1254 FreePool (ProvNameStr);\r
1255 \r
1256 mUsbInfoHandle->Info[3] = Info;\r
1257 mUsbInfoHandle->Count++;\r
1258 }\r
1259 \r
1260 if (*UserInfo == NULL) {\r
1261 //\r
1262 // Return the first info handle.\r
1263 //\r
1264 *UserInfo = (EFI_USER_INFO_HANDLE) mUsbInfoHandle->Info[0];\r
1265 return EFI_SUCCESS;\r
1266 }\r
1267 \r
1268 //\r
1269 // Find information handle in credential info table.\r
1270 //\r
1271 for (Index = 0; Index < mUsbInfoHandle->Count; Index++) {\r
1272 Info = mUsbInfoHandle->Info[Index];\r
1273 if (*UserInfo == (EFI_USER_INFO_HANDLE)Info) {\r
1274 //\r
1275 // The handle is found, get the next one.\r
1276 //\r
1277 if (Index == mUsbInfoHandle->Count - 1) {\r
1278 //\r
1279 // Already last one.\r
1280 //\r
1281 *UserInfo = NULL;\r
1282 return EFI_NOT_FOUND;\r
1283 }\r
1284 Index++;\r
1285 *UserInfo = (EFI_USER_INFO_HANDLE)mUsbInfoHandle->Info[Index];\r
1286 return EFI_SUCCESS; \r
1287 }\r
1288 }\r
1289\r
1290 *UserInfo = NULL;\r
1291 return EFI_NOT_FOUND;\r
1292}\r
1293\r
1294\r
6f0b8648 1295/**\r
1296 Delete a user on this credential provider.\r
1297\r
1298 This function deletes a user on this credential provider. \r
1299\r
1300 @param[in] This Points to this instance of the EFI_USER_CREDENTIAL2_PROTOCOL.\r
1301 @param[in] User The user profile handle to delete.\r
1302\r
1303 @retval EFI_SUCCESS User profile was successfully deleted.\r
1304 @retval EFI_ACCESS_DENIED Current user profile does not permit deletion on the user profile handle. \r
1305 Either the user profile cannot delete on any user profile or cannot delete \r
1306 on a user profile other than the current user profile. \r
1307 @retval EFI_UNSUPPORTED This credential provider does not support deletion in the pre-OS.\r
1308 @retval EFI_DEVICE_ERROR The new credential could not be deleted because of a device error.\r
1309 @retval EFI_INVALID_PARAMETER User does not refer to a valid user profile handle.\r
1310**/\r
1311EFI_STATUS\r
1312EFIAPI\r
1313CredentialDelete (\r
1314 IN CONST EFI_USER_CREDENTIAL2_PROTOCOL *This,\r
1315 IN EFI_USER_PROFILE_HANDLE User\r
1316 )\r
1317{\r
1318 EFI_STATUS Status;\r
1319 EFI_USER_INFO *UserInfo;\r
1320 UINT8 *UserId;\r
1321 UINT8 *NewUserId;\r
1322 UINTN Index;\r
1323 \r
1324 if ((This == NULL) || (User == NULL)) {\r
1325 return EFI_INVALID_PARAMETER;\r
1326 }\r
1327\r
1328 //\r
1329 // Get User Identifier.\r
1330 //\r
1331 UserInfo = NULL;\r
1332 Status = FindUserInfoByType (\r
1333 User,\r
1334 EFI_USER_INFO_IDENTIFIER_RECORD,\r
1335 &UserInfo\r
1336 );\r
1337 if (EFI_ERROR (Status)) {\r
1338 return EFI_INVALID_PARAMETER;\r
1339 }\r
1340\r
1341 //\r
1342 // Find the user by user identifier in mPwdTable.\r
1343 // \r
1344 for (Index = 0; Index < mUsbTable->Count; Index++) {\r
1345 UserId = (UINT8 *) &mUsbTable->UserInfo[Index].UserId;\r
1346 NewUserId = (UINT8 *) (UserInfo + 1);\r
1347 if (CompareMem (UserId, NewUserId, sizeof (EFI_USER_INFO_IDENTIFIER)) == 0) {\r
1348 //\r
1349 // Found the user, delete it.\r
1350 //\r
1351 ModifyTable (Index, NULL);\r
1352 break;\r
1353 }\r
1354 }\r
1355\r
1356 FreePool (UserInfo);\r
1357 return EFI_SUCCESS;\r
1358}\r
1359\r
1360\r
0c18794e 1361/**\r
1362 Main entry for this driver.\r
1363\r
1364 @param ImageHandle Image handle this driver.\r
1365 @param SystemTable Pointer to SystemTable.\r
1366\r
1367 @retval EFI_SUCESS This function always complete successfully.\r
1368\r
1369**/\r
1370EFI_STATUS\r
1371EFIAPI\r
1372UsbProviderInit (\r
1373 IN EFI_HANDLE ImageHandle,\r
1374 IN EFI_SYSTEM_TABLE *SystemTable\r
1375 )\r
1376{\r
1377 EFI_STATUS Status;\r
1378\r
68d151bb
DG
1379 //\r
1380 // It is NOT robust enough to be included in production.\r
1381 //\r
1382 #error "This implementation is just a sample, please comment this line if you really want to use this driver."\r
1383\r
0c18794e 1384 //\r
1385 // Init credential table.\r
1386 //\r
1387 Status = InitCredentialTable ();\r
1388 if (EFI_ERROR (Status)) {\r
1389 return Status;\r
1390 }\r
1391 \r
1392 //\r
1393 // Init Form Browser\r
1394 //\r
1395 Status = InitFormBrowser ();\r
1396 if (EFI_ERROR (Status)) {\r
1397 return Status;\r
1398 }\r
1399 \r
1400 //\r
1401 // Install protocol interfaces for the Usb Credential Provider.\r
1402 //\r
1403 Status = gBS->InstallProtocolInterface (\r
1404 &mCallbackInfo->DriverHandle,\r
6f0b8648 1405 &gEfiUserCredential2ProtocolGuid,\r
0c18794e 1406 EFI_NATIVE_INTERFACE,\r
1407 &gUsbCredentialProviderDriver\r
1408 );\r
1409 return Status;\r
1410}\r