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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
|
/** @file
Picture password
Copyright (c) 2016. Disk Cryptography Services for EFI (DCS), Alex Kolotnikov
Copyright (c) 2016. VeraCrypt, Mounir IDRASSI
This program and the accompanying materials
are licensed and made available under the terms and conditions
of the GNU Lesser General Public License, version 3.0 (LGPL-3.0).
The full text of the license may be found at
https://opensource.org/licenses/LGPL-3.0
**/
#include <Uefi.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/CommonLib.h>
#include <Library/GraphLib.h>
#include <Library/PasswordLib.h>
CHAR16* gPasswordPictureFileName = NULL;
CHAR8* gPasswordPictureChars = NULL;
CHAR8* gPasswordPictureCharsDefault = "MN/[aQ-eyPr}GT: |V^UqiI_gbdA9YwZ%f8t6S@D\"7uXl\\30R#+zH*,W4J?=&BLFv]hx~E;$<.o'sp1`(>C)O{!5j2nmkcK";
//CHAR8* gPicturePasswordCharsDefault = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
UINTN gPasswordPictureCharsLen = 95;
UINT8 gPasswordVisible = 0;
int gPasswordShowMark = 1;
UINT8 gPasswordProgress = 1;
int gPasswordTimeout = 0;
UINTN gKeyboardInputDelay = 100;
int gPlatformLocked = 0;
int gTPMLocked = 0;
int gTPMLockedInfoDelay = 9;
int gSCLocked = 0;
//////////////////////////////////////////////////////////////////////////
// Picture password
//////////////////////////////////////////////////////////////////////////
CONST CHAR16* BmpName = L"Test.bmp";
VOID* gPictPwdBmp = NULL;
UINTN gPictPwdBmpSize = 0;
BLT_HEADER* bltPwd = NULL;
UINTN posPictX, posPictY;
BLT_HEADER* bltScrn = NULL;
UINTN* cellSelected = NULL;
UINTN picPwdIdx = 0;
UINTN sHeight;
UINTN sWidth;
UINTN step;
DRAW_CONTEXT ctxCursor;
DRAW_CONTEXT ctxCell;
DRAW_CONTEXT ctxMark;
DRAW_CONTEXT ctxSet;
VOID
CellUpdate(
IN OUT BLT_HEADER* blt,
IN UINTN x,
IN UINTN y,
IN BOOLEAN selected) {
if (selected && gPasswordShowMark) {
BltCircle(blt, &ctxMark, (INT32)(x * step + step / 2), (INT32)(y * step + step / 2), (INT32)(step / 3), TRUE);
BltCircle(blt, &ctxCell, (INT32)(x * step + step / 2), (INT32)(y * step + step / 2), (INT32)(step / 9), TRUE);
}
else {
CHAR8 ch[2] = { 0,0 };
BltCircle(blt, &ctxCell, (INT32)(x * step + step / 2), (INT32)(y * step + step / 2), (INT32)(step / 3), FALSE);
if (gPasswordVisible) {
ch[0] = gPasswordPictureChars[(x + blt->Width / step * y) % gPasswordPictureCharsLen];
BltText(blt, &ctxCell, (INT32)(x * step + step / 2 - 12), (INT32)(y * step + step / 2 - 12), 256, ch);
}
}
}
BOOLEAN
CellGetSelected(
IN OUT BLT_HEADER* blt,
IN UINTN x,
IN UINTN y,
OUT UINTN* cellX,
OUT UINTN* cellY) {
RECT reg;
UINTN sen;
if (x > blt->Width || y > blt->Height) return FALSE;
*cellX = x / step;
*cellY = y / step;
sen = step / 5; // zone sensible
reg.left = (UINT32)(*cellX * step + step / 2 - sen);
reg.right = (UINT32)(*cellX * step + step / 2 + sen);
reg.top = (UINT32)(*cellY * step + step / 2 - sen);
reg.bottom = (UINT32)(*cellY * step + step / 2 + sen);
return (x > reg.left && x < reg.right && y > reg.top && y < reg.bottom);
}
VOID
DrawCursor(IN OUT BLT_HEADER* blt,
IN UINTN x,
IN UINTN y
) {
BltLine(blt, &ctxCursor, (INT32)(x - 10), (INT32)y, (INT32)(x + 10), (INT32)y);
BltLine(blt, &ctxCursor, (INT32)x, (INT32)(y - 10), (INT32)x, (INT32)(y + 10));
}
typedef struct _TOUCH_ZONE {
UINTN Zone;
CHAR8* Message;
UINTN RetCode;
INT32 TextScale;
} TOUCH_ZONE, *PTOUCH_ZONE;
enum TouchZoneIds {
tznLogin = 1,
tznBeep,
tznShow,
tznChange
};
CHAR8* msgLogin = "LOGIN";
CHAR8* msgBeepOn = "Beep\non";
CHAR8* msgBeepOff = "Beep\noff";
CHAR8* msgChg = "Change\npwd";
CHAR8* msgShowPwd = "Show\npwd";
CHAR8* msgHidePwd = "Hide\npwd";
CHAR8* msgNewPwd = "New\npwd";
CHAR8* msgConfirmPwd = "Confirm\npwd";
CHAR8* msgPlatformLocked = "PLT\nlkd";
CHAR8* msgPlatformUnLocked = "PLT\nunlkd";
CHAR8* msgTpmLocked = "TPM\nlkd";
CHAR8* msgTpmUnLocked = "TPM\nunlkd";
CHAR8* msgSCLocked = "SC\nlkd";
CHAR8* msgSCUnLocked = "SC\nunlkd";
TOUCH_ZONE TZN_Login = { 0, NULL, tznLogin, 128 };
TOUCH_ZONE TZN_Speaker = { 2, NULL, tznBeep, 64 };
TOUCH_ZONE TZN_Show = { 3, NULL, tznShow, 64 };
TOUCH_ZONE TZN_Change = { 5, NULL, tznChange, 32 };
TOUCH_ZONE TZN_Platform = { 6, NULL, 0, 32 };
TOUCH_ZONE TZN_Tpm = { 7, NULL, 0, 32 };
TOUCH_ZONE TZN_SC = { 8, NULL, 0, 32 };
VOID
DrawTouchZone(
IN PTOUCH_ZONE zone
) {
BltFill(bltScrn, gColorBlack, (INT32)(sWidth - step), (INT32)(2 + zone->Zone * step), (INT32)(INT32)(sWidth - 2), (INT32)(step + zone->Zone * step));
BltBox(bltScrn, &ctxCell, (INT32)(sWidth - step), (INT32)(2 + zone->Zone * step), (INT32)(INT32)(sWidth - 2), (INT32)(step + zone->Zone * step));
BltText(bltScrn, &ctxCell, (INT32)(sWidth - step * 3 / 4), (INT32)(step * 1 / 3 + zone->Zone * step), 128, zone->Message);
}
BOOLEAN
IsTouchZone(
IN PTOUCH_ZONE zone,
IN UINTN x,
IN UINTN y
) {
if (x > sWidth - step &&
(y > (zone->Zone * step)) &&
(y < (step + zone->Zone * step))) {
return TRUE;
}
return FALSE;
}
VOID
DrawPwdZone(
IN CHAR8* pwd,
IN UINT32 pwdMax)
{
INT32 pwdGrphMaxLen = (INT32)(sWidth - 2 * step);
BltFill(bltScrn, gColorBlack, 0, 0, (INT32)(sWidth - 2 * step), (INT32)(posPictY));
if (gPasswordProgress || gPasswordVisible) {
if (gPasswordVisible) {
BltText(bltScrn, &ctxCell, 0, 0, 256, pwd);
}
else {
INT32 pwdGrphLen = (INT32)(pwdGrphMaxLen * picPwdIdx / pwdMax);
INT32 pwdGrphHeight = (INT32)(posPictY) / 2;
INT32 pwdGrphTop = (INT32)(posPictY) / 4;
BltFill(bltScrn, gColorGreen, 0, pwdGrphTop, pwdGrphLen, pwdGrphHeight + pwdGrphTop);
BltFill(bltScrn, gColorBlack, pwdGrphLen, pwdGrphTop, pwdGrphMaxLen, pwdGrphHeight + pwdGrphTop);
}
}
}
EFI_STATUS
DrawPwdPicture()
{
EFI_STATUS res;
UINTN idx;
UINTN cellX, cellY;
if (bltPwd != NULL) MEM_FREE(bltPwd);
res = BmpToBlt(gPictPwdBmp, gPictPwdBmpSize, &bltPwd);
if (EFI_ERROR(res)) {
return res;
}
cellY = 0;
do {
cellX = 0;
do {
CellUpdate(bltPwd, cellX, cellY, FALSE);
cellX++;
} while ((cellX + 1) * step <= (bltPwd->Width));
cellY++;
} while ((cellY + 1)* step <= (bltPwd->Height));
// Update selected
for (idx = 0; idx < picPwdIdx; ++idx) {
if (cellSelected[idx * 2] != MAX_INTN) {
CellUpdate(bltPwd, cellSelected[idx * 2], cellSelected[idx * 2 + 1], TRUE);
}
}
return EFI_SUCCESS;
}
VOID
CreateDraws() {
// Set
ctxSet.Color = gColorGray;
ctxSet.DashLine = 0xFFFFFFFF;
ctxSet.Op = DrawOpSet;
ctxSet.Brush = NULL;
// Cursor
ctxCursor.Color = gColorWhite;
ctxCursor.DashLine = 0xFFFFFFFF;
ctxCursor.Op = DrawOpXor;
ctxCursor.Brush = NULL;
// Cell
ctxCell.Color = gColorGreen;
ctxCell.DashLine = 0xFFFFFFFF;
ctxCell.Op = DrawOpSet;
ctxCell.Brush = gBrush3;
// Shade (close to black)
ctxMark.AlphaColor = gColorWhite;
ctxMark.Alpha = 128;
ctxMark.Op = DrawOpAlpha;
ctxMark.Brush = NULL;
}
enum PictPwdAction {
PwdActNone = 0,
PwdActLogin,
PwdActCancel,
PwdActChange,
PwdActShow,
PwdActBeep,
PwdActNewChar,
PwdActUpdateZones,
};
VOID
AskPictPwdInt(
IN UINTN pwdType,
IN UINTN pwdMax,
OUT CHAR8* pwd,
OUT UINT32* pwdLen,
OUT INT32* retCode
) {
EFI_STATUS res;
UINTN cellX, cellY;
UINTN cellPrevX, cellPrevY;
UINTN curX, curY;
UINTN curPrevX, curPrevY;
EFI_INPUT_KEY key;
EFI_EVENT UpdateEvent;
EFI_EVENT BeepOffEvent;
EFI_EVENT InputEvents[3];
UINTN EventIndex = 0;
UINTN eventsCount = 2;
EFI_ABSOLUTE_POINTER_STATE aps = {0};
BOOLEAN showCursor = FALSE;
BOOLEAN beepOn = FALSE;
UINTN pwdAction = PwdActNone;
CHAR8 pwdNewChar = 0;
if (gPasswordTimeout) {
InputEvents[0] = gST->ConIn->WaitForKey;
eventsCount = 2;
if (gTouchPointer != NULL) {
eventsCount = 3;
InputEvents[2] = gTouchPointer->WaitForInput;
}
gBS->CreateEvent(EVT_TIMER, 0, (EFI_EVENT_NOTIFY)NULL, NULL, &InputEvents[1]);
gBS->SetTimer(InputEvents[1], TimerPeriodic, 10000000 * gPasswordTimeout);
gBS->WaitForEvent(eventsCount, InputEvents, &EventIndex);
gPasswordTimeout = 0;
gBS->CloseEvent(InputEvents[1]);
if (EventIndex == 1) {
*retCode = AskPwdRetCancel;
return;
}
}
InitConsoleControl();
if (gBeepEnabled) {
InitSpeaker();
}
if (gPictPwdBmp == NULL) {
if (gPasswordPictureFileName != NULL) {
res = FileLoad(NULL, (CHAR16*)gPasswordPictureFileName, &gPictPwdBmp, &gPictPwdBmpSize);
if (EFI_ERROR(res)) {
ERR_PRINT(L"File load - %r\n", res);
return;
}
} else {
ERR_PRINT(L"Picture file name undefined\n");
return;
}
}
// Init draws
CreateDraws();
// Init screen
if (bltScrn != NULL) MEM_FREE(bltScrn);
ScreenSaveBlt(&bltScrn);
sWidth = bltScrn->Width;
sHeight = bltScrn->Height;
step = sWidth >> 4;
// Init picture password
picPwdIdx = 0;
res = DrawPwdPicture();
if (EFI_ERROR(res)) {
MEM_FREE(bltScrn);
ERR_PRINT(L"BmpToBlt - %r", res);
return;
}
// Touch zones
switch (pwdType) {
case AskPwdConfirm:
TZN_Login.Message = msgConfirmPwd;
break;
case AskPwdNew:
TZN_Login.Message = msgNewPwd;
break;
case AskPwdLogin:
default:
TZN_Login.Message = msgLogin;
}
DrawTouchZone(&TZN_Login);
if (pwdType == AskPwdLogin) {
TZN_Change.Message = msgChg;
DrawTouchZone(&TZN_Change);
}
if (gBeepControlEnabled) {
TZN_Speaker.Message = gBeepEnabled ? msgBeepOff : msgBeepOn;
DrawTouchZone(&TZN_Speaker);
}
TZN_Platform.Message = gPlatformLocked? msgPlatformLocked : msgPlatformUnLocked;
DrawTouchZone(&TZN_Platform);
TZN_Tpm.Message = gTPMLocked ? msgTpmLocked : msgTpmUnLocked;
DrawTouchZone(&TZN_Tpm);
TZN_SC.Message = gSCLocked ? msgSCLocked : msgSCUnLocked;
DrawTouchZone(&TZN_SC);
TZN_Show.Message = gPasswordVisible ? msgHidePwd : msgShowPwd;
DrawTouchZone(&TZN_Show);
cellSelected = MEM_ALLOC(sizeof(UINTN) * 2 * (pwdMax + 1));
ScreenUpdateDirty(bltScrn);
// Prepare cursors
posPictX = (sWidth - bltPwd->Width) >> 1;
posPictY = (sHeight - bltPwd->Height) >> 1;
cellPrevX = MAX_INTN;
cellPrevY = MAX_INTN;
curX = sWidth / 2;
curY = posPictY / 2;
BltDrawBlt(bltScrn, bltPwd, posPictX, posPictY);
// Prepare events
InputEvents[0] = gST->ConIn->WaitForKey;
gBS->CreateEvent(EVT_TIMER, 0, (EFI_EVENT_NOTIFY)NULL, NULL, &InputEvents[1]);
gBS->CreateEvent(EVT_TIMER, 0, (EFI_EVENT_NOTIFY)NULL, NULL, &BeepOffEvent);
gBS->CreateEvent(EVT_TIMER, 0, (EFI_EVENT_NOTIFY)NULL, NULL, &UpdateEvent);
gBS->SetTimer(UpdateEvent, TimerRelative, 500000); // 20 times per second to update
gBS->SetTimer(BeepOffEvent, TimerRelative, gBeepDurationDefault * 10);
gBS->SetTimer(InputEvents[1], TimerRelative, 5000000);
if (gTouchPointer != NULL) {
eventsCount = 3;
InputEvents[2] = gTouchPointer->WaitForInput;
while (gBS->CheckEvent(InputEvents[2]) == EFI_SUCCESS) {
gTouchPointer->GetState(gTouchPointer, &aps);
}
}
while (gBS->CheckEvent(InputEvents[0]) == EFI_SUCCESS) {
gST->ConIn->ReadKeyStroke(gST->ConIn, &key);
}
do
{
curPrevX = curX;
curPrevY = curY;
ZeroMem(&key, sizeof(key));
res = gBS->WaitForEvent(eventsCount, InputEvents, &EventIndex);
if (EventIndex == 0) {
res = gST->ConIn->ReadKeyStroke(gST->ConIn, &key);
if (EFI_ERROR(res)) {
continue;
}
}
// OUT_PRINT(L" \r%05d %05d", (UINT32)curX, (UINT32)curY, );
// recharge timeout event and stop beep
if (gBeepControlEnabled && gBeepEnabled && beepOn) {
if (gBS->CheckEvent(BeepOffEvent) == EFI_SUCCESS) {
beepOn = FALSE;
SpeakerBeep((UINT16)gBeepToneDefault, 0, 0, 0);
gBS->SetTimer(InputEvents[1], TimerRelative, 5000000);
}
}
else {
gBS->SetTimer(InputEvents[1], TimerRelative, 5000000);
}
// hide cursor
if (showCursor && EventIndex != 1) {
DrawCursor(bltScrn, curX, curY);
showCursor = FALSE;
}
// Blink cursor
if (EventIndex == 1) {
DrawCursor(bltScrn, curX, curY);
showCursor = !showCursor;
}
if (EventIndex == 0) {
// gST->ConIn->ReadKeyStroke(gST->ConIn, &key);
// OUT_PRINT(L" %04x, %04x\r", key.ScanCode, key.UnicodeChar);
// Remove dirty chars 0.1s
FlushInputDelay(100000);
switch (key.ScanCode)
{
case SCAN_HOME:
curX -= gTouchSimulateStep;
curY -= gTouchSimulateStep;
break;
case SCAN_LEFT:
curX -= gTouchSimulateStep;
break;
case SCAN_END:
curX -= gTouchSimulateStep;
curY += gTouchSimulateStep;
break;
case SCAN_DOWN:
curY += gTouchSimulateStep;
break;
case SCAN_PAGE_DOWN:
curX += gTouchSimulateStep;
curY += gTouchSimulateStep;
break;
case SCAN_RIGHT:
curX += gTouchSimulateStep;
break;
case SCAN_PAGE_UP:
curX += gTouchSimulateStep;
curY -= gTouchSimulateStep;
break;
case SCAN_UP:
curY -= gTouchSimulateStep;
break;
case SCAN_F11:
if (gTouchSimulateStep > 1)
gTouchSimulateStep--;
break;
case SCAN_F12:
gTouchSimulateStep++;
break;
case SCAN_ESC:
pwdAction = PwdActCancel;
break;
case SCAN_F2:
if (pwdType == AskPwdLogin) {
pwdAction = PwdActChange;
}
break;
case SCAN_F4:
if (gBeepControlEnabled) {
pwdAction = PwdActBeep;
}
break;
case SCAN_F5:
pwdAction = PwdActShow;
break;
case SCAN_F7:
gPlatformLocked = gPlatformLocked ? 0 : 1;
pwdAction = PwdActUpdateZones;
break;
case SCAN_F8:
gTPMLocked = gTPMLocked ? 0 : 1;
pwdAction = PwdActUpdateZones;
break;
case SCAN_F9:
gSCLocked = gSCLocked ? 0 : 1;
pwdAction = PwdActUpdateZones;
break;
default:
;
}
if (key.UnicodeChar != 0) {
if (key.UnicodeChar == 0x0d) {
pwdAction = PwdActLogin;
}
else {
pwdNewChar = (CHAR8)key.UnicodeChar;
pwdAction = PwdActNewChar;
cellSelected[picPwdIdx * 2] = MAX_INTN;
}
}
}
if (EventIndex == 2) {
res = gTouchPointer->GetState(gTouchPointer, &aps);
if (!EFI_ERROR(res)) {
curX = (UINTN)(aps.CurrentX * sWidth / (gTouchPointer->Mode->AbsoluteMaxX - gTouchPointer->Mode->AbsoluteMinX));
curY = (UINTN)(aps.CurrentY * sHeight / (gTouchPointer->Mode->AbsoluteMaxY - gTouchPointer->Mode->AbsoluteMinY));
}
}
if (curX > sWidth) curX = sWidth;
if (curY > sHeight) curY = sHeight;
// Cell check
if (CellGetSelected(bltPwd, curX - posPictX, curY - posPictY, &cellX, &cellY) && picPwdIdx < pwdMax) {
if (cellPrevX != cellX || cellPrevY != cellY) {
cellPrevX = cellX;
cellPrevY = cellY;
cellSelected[picPwdIdx * 2] = cellX;
cellSelected[picPwdIdx * 2 + 1] = cellY;
CellUpdate(bltPwd, cellX, cellY, TRUE);
BltDrawBlt(bltScrn, bltPwd, posPictX, posPictY);
pwdAction = PwdActNewChar;
pwdNewChar = gPasswordPictureChars[(cellX + bltPwd->Width / step * cellY) % gPasswordPictureCharsLen];
}
else if (EventIndex == 2 && aps.ActiveButtons == 0) {
cellPrevX = MAX_INTN;
cellPrevY = MAX_INTN;
curX = posPictX + cellX * step;
curY = posPictY + cellY * step;
while (gBS->CheckEvent(InputEvents[2]) == EFI_SUCCESS) {
gTouchPointer->GetState(gTouchPointer, &aps);
}
}
}
if (pwdAction == PwdActNone) {
if (IsTouchZone(&TZN_Login, curX, curY)) {
pwdAction = PwdActLogin;
}
if (pwdType == AskPwdLogin && IsTouchZone(&TZN_Change, curX, curY)) {
pwdAction = PwdActChange;
}
if (curPrevX != curX || curPrevY != curY) {
if (gSpeakerCount > 0 && IsTouchZone(&TZN_Speaker, curX, curY)) {
pwdAction = PwdActBeep;
}
if (IsTouchZone(&TZN_Show, curX, curY)) {
pwdAction = PwdActShow;
}
if (IsTouchZone(&TZN_Tpm, curX, curY)) {
gTPMLocked = gTPMLocked ? 0 : 1;
pwdAction = PwdActUpdateZones;
}
if (IsTouchZone(&TZN_Platform, curX, curY)) {
gPlatformLocked = gPlatformLocked ? 0 : 1;
pwdAction = PwdActUpdateZones;
}
if (IsTouchZone(&TZN_SC, curX, curY)) {
gSCLocked = gSCLocked ? 0 : 1;
pwdAction = PwdActUpdateZones;
}
}
}
if (PwdActNewChar == pwdAction) {
BOOLEAN bUpdPwdZone = FALSE;
if (pwdNewChar == '\b' && picPwdIdx > 0) {
picPwdIdx--;
pwd[picPwdIdx] = 0;
bUpdPwdZone = TRUE;
} else if ((picPwdIdx < pwdMax - 1) && (pwdNewChar >= 32)) {
pwd[picPwdIdx++] = pwdNewChar;
pwd[picPwdIdx] = 0;
bUpdPwdZone = TRUE;
}
if(bUpdPwdZone) {
*pwdLen = (int)picPwdIdx;
DrawPwdZone(pwd, (INT32)pwdMax);
if (gBeepControlEnabled && gBeepEnabled) {
SpeakerBeep((UINT16)gBeepToneDefault, gBeepNumberDefault, 0, 0);
gBS->SetTimer(BeepOffEvent, TimerRelative, gBeepDurationDefault * 10);
gBS->SetTimer(InputEvents[1], TimerRelative, gBeepDurationDefault * 10);
beepOn = TRUE;
}
}
}
else if (PwdActBeep == pwdAction && gBeepControlEnabled) {
if (gBeepEnabled && beepOn) {
beepOn = FALSE;
SpeakerBeep((UINT16)gBeepToneDefault, 0, 0, 0);
}
gBeepEnabled = gBeepEnabled ? 0 : 1;
TZN_Speaker.Message = gBeepEnabled ? msgBeepOff : msgBeepOn;
DrawTouchZone(&TZN_Speaker);
}
else if (PwdActShow == pwdAction) {
gPasswordVisible = gPasswordVisible ? 0 : 1;
DrawPwdZone(pwd, (INT32)pwdMax);
DrawPwdPicture();
BltDrawBlt(bltScrn, bltPwd, posPictX, posPictY);
TZN_Show.Message = gPasswordVisible ? msgHidePwd : msgShowPwd;
DrawTouchZone(&TZN_Show);
}
else if (PwdActLogin == pwdAction) {
*retCode = AskPwdRetLogin;
break;
}
else if (pwdType == AskPwdLogin && PwdActChange == pwdAction) {
*retCode = AskPwdRetChange;
break;
}
else if (PwdActCancel == pwdAction){
*retCode = AskPwdRetCancel;
break;
}
else if (PwdActUpdateZones == pwdAction) {
TZN_Platform.Message = gPlatformLocked ? msgPlatformLocked : msgPlatformUnLocked;
DrawTouchZone(&TZN_Platform);
TZN_Tpm.Message = gTPMLocked ? msgTpmLocked : msgTpmUnLocked;
DrawTouchZone(&TZN_Tpm);
TZN_SC.Message = gSCLocked ? msgSCLocked : msgSCUnLocked;
DrawTouchZone(&TZN_SC);
}
if ((curPrevX != curX || curPrevY != curY) && (EventIndex != 2)) {
DrawCursor(bltScrn, curX, curY);
showCursor = TRUE;
}
// Time to update screen?
if (gBS->CheckEvent(UpdateEvent) == EFI_SUCCESS) {
ScreenUpdateDirty(bltScrn);
gBS->SetTimer(UpdateEvent, TimerRelative, 500000); // 20 times per second to update
}
pwdAction = PwdActNone;
} while (TRUE);
MEM_BURN (&key, sizeof (key));
MEM_BURN (&pwdNewChar, sizeof (pwdNewChar));
gBS->CloseEvent(InputEvents[1]);
gBS->CloseEvent(UpdateEvent);
gBS->CloseEvent(BeepOffEvent);
ScreenFillRect(&gColorBlack, 0, 0, sWidth, sHeight);
gBS->Stall(500000);
}
|