summaryrefslogtreecommitdiff
path: root/Core/EM/HddSecurity/IdeSecurity.h
blob: dbc6a1834f0bc8bf24694fc9320de822b7033935 (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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2015, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**         5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093        **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************

//**********************************************************************
// $Header: /Alaska/SOURCE/Modules/HddSecurity/IdeSecurity.h 13    4/22/15 3:57a Anbuprakashp $
//
// $Revision: 13 $
//
// $Date: 4/22/15 3:57a $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/HddSecurity/IdeSecurity.h $
// 
// 13    4/22/15 3:57a Anbuprakashp
// [TAG]  		EIP212319
// [Category]  	Bug Fix
// [Severity]  	Normal
// [Symptom]  	System hang while SW_SMI_AHCI_LOCATE_AHCI_SMM SMI trigger
// after enable SmmChkEn bit
// [RootCause]  	Bootservice call used inside IdeSmm driver which causes
// the Exception
// [Solution]  	Changes made not to use BootService calls inside IdeSmm
// driver
// [Files]  		IdeSecurity.h
// IdeSecurity.c
// IDESMM.c
// 
// 12    10/11/11 1:54a Rameshr
// [TAG]  		EIP69246
// [Category]  	Improvement
// [Description]  	Made the  SECURITY_SUPPORT as the Master token and
// removed the IdeSecurity_Support token.
// [Files]  		IdeSecurity.c, IdeSecurity.h, IdeSecurity.mak,
// IdeSecurity.sdl
// 
// 11    4/06/11 12:53a Rameshr
// [TAG]- EIP 57341
// [Category]-IMPROVEMENT
// [Description]- Added Support for SMM PI 1.1 in HDDSecurity eModule.
// [Files]- IdeSecurity.c , IdeSecurity.h, IdeSecurity.dxs
// 
// 10    10/13/10 4:26a Rameshr
// [TAG] - EIP 43790
// [Category]- BUG FIX
// [Severity]- Minor
// [Symptom] - The IDE_SECURITY_PWNV_GUID in IdeSecurity.h will cause
// compile failed in some case
// [RootCause] - The definition of IDE_SECURITY_PWNV_GUID contains a
// semicolon in the end of line
// [Solution] - Removed the SemiColon in the end of line 
// [Files] - IdeSecurity.h
// 
// 9     9/20/10 4:16a Rameshr
// [TAG]- EIP 44182
// [Category]-IMPROVEMENT
// [Description]- Unable to build the project with HDDSecurity module and
// without AHCI module.
// [Files]- IdeSecurity.h, IdeSmm.c
// 
// 8     2/19/10 12:48p Yul
// Delete the comment out codes.
// 
// 7     1/21/10 12:07p Yul
// Refer to EIP 33848 
// LegacyBios protocol is not needed here.
// 
// 6     1/15/10 10:21a Yul
// Coding Standard
//
// 5     11/25/09 6:03p Krishnakumarg
// Removed Tab spaces to comply with AMI coding standard.
//
// 4     7/14/09 1:55p Pats
// EIP 22925: Request to set HDD password length by token.
// Solution: Token added to IdeSecurity.sdl, and definition removed from
// IdeSecurity.h
//
// 3     4/28/09 6:46p Rameshr
// HDD password support in RAID mode
// EIP:20421
//
// 2     4/11/08 4:28p Rameshraju
// 1)Enter the Emptry string for the master password, will set the default
// OEM password and in setup password status will be not installed.
// 2)If the revision code is not 0, then SecuritySetPassword will use
// revision code from the input parameters.
// 3)HddSecutiyData Nvram variable master password cleared when we set
// user password and user password cleared when we set master password.
// 4)When we disable the password, HddSecutiyData Nvram variable also
// updated properly.
// 5)Password lenght stored in HddSecData structure.
//
// 1     28/02/08 6:40p Anandakrishnanl
// Created new HddSecurity module.  Isolated IdeSecurity and IdeSmm from
// IdeBus driver to be compatable with the AHCI Bus driver.
//
//
//<AMI_FHDR_START>
//----------------------------------------------------------------------------
//
// Name:    <IdeSecurity.h>
//
// Description: This file contains the Includes, Definitions, typedefs,
//              Variable and External Declarations, Structure and
//              function prototypes needed for the IdeSecurity driver
//
//----------------------------------------------------------------------------
//<AMI_FHDR_END>

#ifndef _IdeSecurity_
#define _IdeSecurity_

#ifdef __cplusplus
extern "C" {
#endif

#include <Efi.h>
#include <Token.h>
#include <Dxe.h>
#include <AmiDxeLib.h>
#include "Protocol\PciIo.h"
#include "Protocol\DevicePath.h"
#include "protocol\DriverBinding.h"
#include "protocol\BlockIo.h"
#include "Protocol\PDiskInfo.h"
#include "Protocol\PIDEController.h"
#include "Protocol\PIDEBus.h"
#include "Protocol\PAhciBus.h"
#include <Protocol\ComponentName.h>
#include <Protocol\BootScriptSave.h>
#include <Protocol\SmmBase.h>
#include <Protocol\SmmCommunication.h>
#if defined(PI_SPECIFICATION_VERSION)&&(PI_SPECIFICATION_VERSION>=0x0001000A)
#include <Protocol\SmmControl2.h>
#else
#include <Protocol\SmmControl.h>
#endif
#if ( defined(AhciSrc_SUPPORT) && (AhciSrc_SUPPORT != 0) )
#include <Protocol\AhciSmmProtocol.h>
#endif

#define IDE_SECURITY_PWNV_GUID \
{ 0x69967a8c, 0x1159, 0x4522, 0xaa, 0x89, 0x74, 0xcd, 0xc6, 0xe5, 0x99, 0xa0}

#define EFI_SMM_SAVE_HDD_PASSWORD_GUID \
    { 0xeedcf975, 0x4dd3, 0x4d94, 0x96, 0xff, 0xaa, 0xca, 0x83, 0x53, 0xb8, 0x7b }

#define EFI_SMM_REMOVE_HDD_PASSWORD_GUID \
    { 0xc2b1e795, 0xf9c5, 0x4829, 0x8a, 0x42, 0xc0, 0xb3, 0xfe, 0x57, 0x15, 0x17 }

#define AMI_LOCATE_IDE_AHCI_PROTOCOL_GUID \
    { 0xb3f096e9, 0x2d46, 0x4e8e, 0xa2, 0x2c, 0x7d, 0xe8, 0xb1, 0x6b, 0x3a, 0x5b }

#define HDD_PWD_ENCRYPTION_KEY      "H?p1mA*k920_84o3d^!z@L.x4$kY64"

#define EFI_SEGMENT( _Adr )     (UINT16) ((UINT16) (((UINTN) (_Adr))\
                                                    >> 4) & 0xf000)
#define EFI_OFFSET( _Adr )      (UINT16) (((UINT16) ((UINTN) (_Adr))) & 0xffff)


//###DEBUG  Uncomment the following for Required Debug Level.

//#define   TRACE_IDESMM TRACE

//###DEBUG END

#define     TRACE_IDESMM

#define     ZeroMemory( Buffer, Size ) pBS->SetMem( Buffer, Size, 0 )

// Forward reference for pure ANSI compatability
typedef struct _IDE_BUS_PROTOCOL IDE_BUS_PROTOCOL;

HDD_SECURITY_INIT_PROTOCOL *gHddSecurityInitProtocol;

EFI_GUID gSaveHddPasswordGuid=EFI_SMM_SAVE_HDD_PASSWORD_GUID;
EFI_GUID gRemoveHddPasswordGuid=EFI_SMM_REMOVE_HDD_PASSWORD_GUID;
EFI_GUID gLocateIdeAhciSmmProtocolGuid=AMI_LOCATE_IDE_AHCI_PROTOCOL_GUID;
EFI_GUID gEfiSmmCommunicationProtocolGuid=EFI_SMM_COMMUNICATION_PROTOCOL_GUID;

#pragma pack(1)

typedef struct
{
    UINT8  Bus;
    UINT8  Device;
    UINT8  Function;
    UINT8  Controller;
    UINT32 Reserved;
} EDD_PCI;

typedef struct
{
    UINT16 Base;
    UINT16 Reserved;
    UINT32 Reserved2;
} EDD_LEGACY;

typedef union
{
    EDD_PCI    Pci;
    EDD_LEGACY Legacy;
} EDD_INTERFACE_PATH;

typedef struct
{
    UINT8 Master;
    UINT8 Reserved[15];
} EDD_ATA;

typedef struct
{
    UINT8 Master;
    UINT8 Lun;
    UINT8 Reserved[14];
} EDD_ATAPI;

typedef struct
{
    UINT16 TargetId;
    UINT64 Lun;
    UINT8  Reserved[6];
} EDD_SCSI;

typedef struct
{
    UINT64 SerialNumber;
    UINT64 Reserved;
} EDD_USB;

typedef struct
{
    UINT64 Guid;
    UINT64 Reserved;
} EDD_1394;

typedef struct
{
    UINT64 Wwn;
    UINT64 Lun;
} EDD_FIBRE;

typedef struct
{
    UINT8 bPortNum;
    UINT8 Reserved[15];
} EDD_SATA;

typedef union
{
    EDD_ATA   Ata;
    EDD_ATAPI Atapi;
    EDD_SCSI  Scsi;
    EDD_USB   Usb;
    EDD_1394  FireWire;
    EDD_FIBRE FibreChannel;
    EDD_SATA  Sata;
} EDD_DEVICE_PATH;

typedef struct
{
    UINT16             StructureSize;
    UINT16             Flags;
    UINT32             MaxCylinders;
    UINT32             MaxHeads;
    UINT32             SectorsPerTrack;
    UINT64             PhysicalSectors;
    UINT16             BytesPerSector;
    UINT32             FDPT;
    UINT16             Key;
    UINT8              DevicePathLength;
    UINT8              Reserved1;
    UINT16             Reserved2;
    CHAR8              HostBusType[4];
    CHAR8              InterfaceType[8];
    EDD_INTERFACE_PATH InterfacePath;
    EDD_DEVICE_PATH    DevicePath;
    UINT8              Reserved3;
    UINT8              Checksum;
} EDD_DRIVE_PARAMETERS;

typedef struct _HDDSECDATA
{
    UINT16 UserMaster;
    UINT32 PasswordLength;
    UINT8  HddUserPassword[IDE_PASSWORD_LENGTH];
    UINT8  HddMasterPassword[IDE_PASSWORD_LENGTH];
} HDDSECDATA;

#pragma pack()



EFI_STATUS InstallSecurityInterface (
    IN VOID    *BusInterface,
    IN BOOLEAN ModeFlag );

EFI_STATUS StopSecurityModeSupport (
    IN VOID    *BusInterface,
    IN BOOLEAN ModeFlag );

EFI_STATUS ReturnSecurityStatus (
    IN IDE_SECURITY_PROTOCOL *This,
    UINT16                   *SecurityStatus );

EFI_STATUS SecuritySetPassword (
    IN IDE_SECURITY_PROTOCOL *This,
    UINT16                   Control,
    UINT8                    *Buffer,
    UINT16                   RevisionCode );

EFI_STATUS SecurityUnlockPassword (
    IN IDE_SECURITY_PROTOCOL *This,
    UINT16                   Control,
    UINT8                    *Buffer );

EFI_STATUS SecurityDisablePassword (
    IN IDE_SECURITY_PROTOCOL *This,
    UINT16                   Control,
    UINT8                    *Buffer );

EFI_STATUS SetDefaultMasterPassword (
    IN IDE_SECURITY_PROTOCOL *This );

EFI_STATUS SecuritySetDefaultMasterPassword (
    IN IDE_SECURITY_PROTOCOL *This,
    UINT16                   Control,
    UINT8                    *Buffer,
    UINT16                   RevisionCode );

EFI_STATUS SecurityFreezeLock (
    IN IDE_SECURITY_PROTOCOL *This );

EFI_STATUS SecurityEraseUnit (
    IN IDE_SECURITY_PROTOCOL *This,
    UINT16                   Control,
    UINT8                    *Buffer );

EFI_STATUS ReturnIdePasswordFlags (
    IN IDE_SECURITY_PROTOCOL *This,
    UINT32                   *IdePasswordFlags );

EFI_STATUS SecurityCommonRoutine (
    IN VOID *IdeBusInterface,
    UINT16  Control,
    UINT8   *Buffer,
    UINT8   SecurityCommand,
    UINT16  RevisionCode,
    BOOLEAN ModeFlag );

EFI_STATUS ConnectController (
    IN EFI_HANDLE                                   ControllerHandle,
    IN EFI_HANDLE*DriverImageHandle                 OPTIONAL,
    IN EFI_DEVICE_PATH_PROTOCOL*RemainingDevicePath OPTIONAL,
    IN BOOLEAN                                      Recursive );

EFI_STATUS GatherIdeInfo (
    IN VOID    *BusInterface,
    IN BOOLEAN ModeFlag,
    OUT UINT32 *HddDataId );

EFI_STATUS UpdateIdentifyData (
    IN VOID    *BusInterface,
    IN BOOLEAN ModeFlag );

EFI_STATUS SetHddSecDataInNvram (
    IN VOID *BusInterface,
    UINT32  *HddDataId,
    UINT16  Control,
    UINT8   *Buffer );

EFI_STATUS TransferPwDataFromNvramToSmram (
    IN IDE_SECURITY_PROTOCOL *This );

VOID ConvertHddDataIdToString (
    IN UINT32  DataId,
    OUT CHAR16 *String );

VOID EncodeDecodePassword (
    IN UINT8  *InputString,
    OUT UINT8 *OutputString,
    IN UINT32 StringLength );

EFI_STATUS OEMSetMasterPassword (
    IN IDE_SECURITY_PROTOCOL *This );

EFI_STATUS SmmHDDPasswordInterface (
    IN IDE_SECURITY_PROTOCOL *This,
    UINT16                   Control,
    UINT8                    *Buffer,
    UINT8                    Action );

VOID IdeBusCallbackBootScript (
    IN EFI_EVENT Event,
    IN VOID      *Context );

VOID IdeBusMiscSmmFeatureCallback (
    IN EFI_EVENT Event,
    IN VOID      *Context );

BOOLEAN CheckAhciMode (
    IN IDE_BUS_PROTOCOL *IdeBusInterface );

UINTN EfiValueToString (
    IN OUT CHAR16 *Buffer,
    IN INT64      Value,
    IN UINTN      Flags,
    IN UINTN      Width );

EFI_STATUS CommonNonDataHook (
    IN VOID              *BusInterface,
    IN COMMAND_STRUCTURE CommandStructure,
    IN BOOLEAN           ModeFlag );

EFI_STATUS CommonPioDataHook (
    IN VOID              *BusInterface,
    IN COMMAND_STRUCTURE CommandStructure,
    IN BOOLEAN           ModeFlag );

EFI_STATUS CommonReadWritePioHook (
    IN VOID     *BusInterface,
    IN OUT VOID *Buffer,
    IN UINTN    ByteCount,
    IN UINT64   LBA,
    IN UINT8    ReadWriteCommand,
    IN BOOLEAN  ReadWrite,
    IN BOOLEAN  ModeFlag );

EFI_STATUS CommonWfccHook (
    IN VOID    *BusInterface,
    IN BOOLEAN ModeFlag );

VOID LocateAhciSmmServiceEvent (
    EFI_EVENT Event,
    VOID      *Context );



/****** DO NOT WRITE BELOW THIS LINE *******/
#ifdef __cplusplus
}
#endif

#endif

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