summaryrefslogtreecommitdiff
path: root/Core/EM/OFBD/OEMPWDCK/OEMPwdCk.c
blob: 99afa2ad1b0fddca633c29913147b6ce9fdb1a6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2011, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093        **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************

//**********************************************************************
// $Header: /Alaska/SOURCE/Modules/OFBD/OEMPWDCK/OEMPwdCk.c 2     3/16/11 10:34p Terrylin $
//
// $Revision: 2 $
//
// $Date: 3/16/11 10:34p $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/OFBD/OEMPWDCK/OEMPwdCk.c $
// 
// 2     3/16/11 10:34p Terrylin
// [TAG]  		EIP51285
// [Category]  	Improvement
// [Description]  	Fill the description for user more clearly.
// [Files]  		OEMPwdCk.mak
// OEMPwdCk.c
// OEMPwdCk.h
// 
// 1     4/13/09 5:47a Lawrencechang
// Initial check-in.
// 
// 1     3/25/05 5:37p Markw
// 
//**********************************************************************
//<AMI_FHDR_START>
//
// Name:	OEMPwdCk.c
//
// Description:
// Password Check protocol is for BIOS to indicate AFU that BIOS password exists and needs to initiate password
// checking before flashing BIOS. AFU will set OEM_PC_CK in dbGetCkSts field and send OFBD data to BIOS to report
// password checking is required or not.
// 
// If password check function is requested then BIOS should fill out password length in dwPwdLen field. Afterward AFU
// asks user to input password with specified password length given from BIOS in field dwPwdLen and fill user input
// password in memory buffer after signature of OFBD_EXT_TBL_END for BIOS to do the comparison. 
//
//<AMI_FHDR_END>
//**********************************************************************
#include "Efi.h"
#include "token.h"
#include <AmiLib.h>
#include <AmiDxeLib.h>
#include "OEMPwdCk.h"
#include "..\OFBD.h"

static int ErrorNum = 0;
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	OFBDPwdGetHandle
//
// Description:	OFBD Password Get Handle
//
// Input:
//      IN OUT OFBD_HDR *pOFBDHdr
// Output:
//      EFI_STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS
OFBDPwdGetHandle( 
    IN OUT OFBD_HDR *pOFBDHdr)
{
    EFI_STATUS Status = EFI_SUCCESS;

#if OEM_PWDCK_SAMPLE_TEST
    char *DisOemStrPwd1 = "Password";
    char *DisOemStrPwd2 = "Password Retry count exceeded!";
    UINT8 *pOFBDTblEnd;
	OFBD_TC_52_PC_STRUCT *PwdCkStructPtr; 

    pOFBDTblEnd = (UINT8 *)((UINT8 *)pOFBDHdr + (pOFBDHdr->OFBD_Size));
	PwdCkStructPtr = (OFBD_TC_52_PC_STRUCT *)((UINT8 *)pOFBDHdr + pOFBDHdr->OFBD_HDR_SIZE + sizeof(OFBD_EXT_HDR)); 
	PwdCkStructPtr->dbRetSts =  OEM_RS_PC_REQ;
	PwdCkStructPtr->dwPwdLen = 7;
    if(ErrorNum < PASSWORD_RETRY_NUM)
    {
        //pOFBDHdr->OFBD_RS |= OFBD_RS_DIS_OEMSTR;
        //Strcpy((char *)pOFBDTblEnd, DisOemStrPwd1);
    }
    else
    {
        PwdCkStructPtr->dbRetSts |= OEM_RS_PC_TIMES_EXCEEDED;
        //pOFBDHdr->OFBD_RS |= OFBD_RS_DIS_OEMSTR;
        //Strcpy((char *)pOFBDTblEnd, DisOemStrPwd2);
    }
#endif

    return(Status);
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	OFBDPwdCheckHandle
//
// Description:	OFBD Password Check Handle
//
// Input:
//      IN OUT OFBD_HDR *pOFBDHdr
// Output:
//      EFI_STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS
OFBDPwdCheckHandle(
    IN OUT OFBD_HDR *pOFBDHdr)
{
    EFI_STATUS Status = EFI_SUCCESS;

#if OEM_PWDCK_SAMPLE_TEST
    char *DisOemStrPwdOK = "Password Comparison successes!";
    char *DisOemStrPwdErr = "Password Comparison error!";
    char *DisOemStrPwdErr2 = "Password Retry count exceeded!";
    char *Password = "0123456";
	UINT8 *pOFBDTblEnd;
	OFBD_TC_52_PC_STRUCT *PwdCkStructPtr;  
   
	PwdCkStructPtr = (OFBD_TC_52_PC_STRUCT *)((UINT8 *)pOFBDHdr + pOFBDHdr->OFBD_HDR_SIZE + sizeof(OFBD_EXT_HDR)); 
	pOFBDTblEnd = (UINT8 *)((UINT8 *)pOFBDHdr + (pOFBDHdr->OFBD_Size));
	if(!MemCmp(pOFBDTblEnd, Password, PwdCkStructPtr->dwPwdLen))
	{
		PwdCkStructPtr->dbRetSts |= OEM_RS_PC_CK_OK;
        //pOFBDHdr->OFBD_RS |= OFBD_RS_DIS_OEMSTR;
		//Strcpy((char *)pOFBDTblEnd, DisOemStrPwdOK);
	}
	else
	{
        ErrorNum++;
		PwdCkStructPtr->dbRetSts |= 0;
        if(ErrorNum < PASSWORD_RETRY_NUM)
        {
            //pOFBDHdr->OFBD_RS |= OFBD_RS_DIS_OEMSTR;
		    //Strcpy((char *)pOFBDTblEnd,  DisOemStrPwdErr);
        }
        else
        {
            PwdCkStructPtr->dbRetSts |= OEM_RS_PC_TIMES_EXCEEDED;
            //pOFBDHdr->OFBD_RS |= OFBD_RS_DIS_OEMSTR;
		    //Strcpy((char *)pOFBDTblEnd, DisOemStrPwdErr2);
        }
	}

#endif

    return(Status);
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	OFBDEntryPoint
//
// Description:	OFBD OEM Password CHECK Entry Point
//
// Input:
//      IN VOID             *Buffer
//      IN OUT UINT8        *pOFBDDataHandled
// Output:
//      VOID
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID OEMPWDCKEntry (
    IN VOID             *Buffer,
    IN OUT UINT8        *pOFBDDataHandled )
{
    OFBD_HDR *pOFBDHdr;
    OFBD_EXT_HDR *pOFBDExtHdr; 
    VOID *pOFBDTblEnd;
    OFBD_TC_52_PC_STRUCT *PwdCkStructPtr;    

    if(*pOFBDDataHandled == 0)
    {
        pOFBDHdr = (OFBD_HDR *)Buffer;
        pOFBDExtHdr = (OFBD_EXT_HDR *)((UINT8 *)Buffer + (pOFBDHdr->OFBD_HDR_SIZE));
        PwdCkStructPtr = (OFBD_TC_52_PC_STRUCT *)((UINT8 *)pOFBDExtHdr + sizeof(OFBD_EXT_HDR)); 
        pOFBDTblEnd = (VOID *)((UINT8 *)Buffer + (pOFBDHdr->OFBD_Size));    

        //TRACE((-1,"pOFBDHdr address is:%x ------\n",pOFBDHdr));
        //TRACE((-1,"pOFBDTblEnd address is:%x ------\n",*(UINT64 *)((UINT8 *)pOFBDTblEnd -sizeof(OFBD_END))));
        
        if(pOFBDHdr->OFBD_FS & OFBD_FS_PWD)
        {   
            //Check Type Code ID
            if(pOFBDExtHdr->TypeCodeID == OFBD_EXT_TC_PWD)
            {  
                //IoWrite32(0x300, *(UINT32 *)((UINT8 *)pOFBDTblEnd -4)); //debug
				if(PwdCkStructPtr->dbGetCkSts == OFBD_TC_OPC_GET)
				{
					if(OFBDPwdGetHandle(pOFBDHdr) == EFI_SUCCESS)
					{
						//OEM ROM ID Data Handled.
                    	*pOFBDDataHandled = 0xFF;      
                    	return;
                	}
				}
				else if(PwdCkStructPtr->dbGetCkSts == OFBD_TC_OPC_CHECK)
				{
					if(OFBDPwdCheckHandle(pOFBDHdr) == EFI_SUCCESS)
					{
						//OEM ROM ID Data Handled.
                    	*pOFBDDataHandled = 0xFF;      
                    	return;
                	}
				}
                /*//Not OEM ROM ID Data.
                *pOFBDDataHandled = 0;          
                return;*/
            } 
            //else
            //{
                 //Error occured
                *pOFBDDataHandled = 0xFE;          
                return;
            //}
        }  
    }

    return;
}

//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2011, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093        **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************