void remove_password_box (EFI_SYSTEM_TABLE *systab) { EFI_SIMPLE_TEXT_OUT_PROTOCOL *conout = systab->ConOut; conout->SetAttribute (conout, EFI_WHITE | EFI_BACKGROUND_BLACK); conout->ClearScreen(conout); conout->EnableCursor(conout, 1); }
void init_password_box (EFI_SYSTEM_TABLE *systab, struct password_box *pwd_box) { EFI_SIMPLE_TEXT_OUT_PROTOCOL *conout = systab->ConOut; EFI_SIMPLE_TEXT_IN_PROTOCOL *conin = systab->ConIn; UINTN max_mode = systab->ConOut->Mode->MaxMode; EFI_STATUS error; UINTN cols = 0, rows = 0; UINTN max_cols = 0; UINTN max_rows = 0; UINTN best_mode = 0; int i; for (i = 0; i < max_mode; i++) { error = conout->QueryMode(systab->ConOut, i, &cols, &rows); if (!error && cols != 0 && cols <= 512 && rows != 0 && rows <= 512) { if (max_cols < cols) { max_cols = cols; max_rows = rows; best_mode = i; } else if (max_cols == cols && max_rows < rows) { max_rows = rows; best_mode = i; } } } conout->SetMode (conout, best_mode); conout->SetAttribute (conout, BACKGROUND); conout->ClearScreen(conout); conout->EnableCursor(conout, 0); UINTN col_offset = (max_cols - PASS_BOX_COLS) / 2; UINTN row_offset = (max_rows - PASS_BOX_ROWS) / 2; pwd_box->cols = PASS_BOX_COLS; pwd_box->rows = PASS_BOX_ROWS; pwd_box->col_offset = col_offset; pwd_box->row_offset = row_offset; }
static void draw_password_box (EFI_SYSTEM_TABLE *systab, struct password_box *pwd_box, CHAR16 *hint_txt) { EFI_SIMPLE_TEXT_OUT_PROTOCOL *conout = systab->ConOut; int i; for (i = 0; i < pwd_box->cols; i++) { line[i] = ' '; } for (i = 0; i < PASS_FIELD_COLS; i++) { input_line[i] = ' '; } /* Draw box */ conout->SetCursorPosition (conout, pwd_box->col_offset, pwd_box->row_offset); conout->SetAttribute (conout, BOX_BACKGROUND); UINTN row; for (row = 0; row < pwd_box->rows; row++) { conout->OutputString (conout, line); UINTN new_row = pwd_box->row_offset + row; conout->SetCursorPosition (conout, pwd_box->col_offset, new_row); } /* Print box title */ conout->SetAttribute (conout, BOX_TEXT); conout->SetCursorPosition (conout, pwd_box->col_offset, pwd_box->row_offset + 1); conout->OutputString (conout, TXT_HEAD); /* Print hint */ conout->SetCursorPosition (conout, pwd_box->col_offset, pwd_box->row_offset + 5); conout->OutputString (conout, hint_txt); /* Print input field */ conout->SetAttribute (conout, BOX_INPUT); conout->SetCursorPosition (conout, pwd_box->col_offset + 2, pwd_box->row_offset + 3); conout->OutputString (conout, input_line); /* Move cursor to the first input position */ conout->SetAttribute (conout, BOX_INPUT_TEXT); conout->SetCursorPosition (conout, pwd_box->col_offset + 2, pwd_box->row_offset + 3); conout->EnableCursor(conout, 1); }
void get_password (EFI_SYSTEM_TABLE *systab, struct password_box *pwd_box, uint8_t *pass_buf, UINTN buf_nbytes, UINTN *n_chars) { *n_chars = 0; EFI_SIMPLE_TEXT_OUT_PROTOCOL *conout = systab->ConOut; EFI_SIMPLE_TEXT_IN_PROTOCOL *conin = systab->ConIn; EFI_INPUT_KEY input_key; UINTN event_idx; UINTN count = 0; EFI_STATUS error; get_input: conout->EnableCursor(conout, count < PASS_FIELD_COLS); systab->BootServices->WaitForEvent (1, &conin->WaitForKey, &event_idx); error = conin->ReadKeyStroke (conin, &input_key); randseed_event (systab); if (error) { goto get_input; } switch (input_key.UnicodeChar) { case 0x0000: case 0x0009: goto get_input; case 0x0008: /* BS */ pass_buf[count] = 0x00; if (count > 0) { count--; if (count < PASS_FIELD_COLS) { conout->SetAttribute (conout, BOX_INPUT); conout->OutputString (conout, CHAR_REMOVE); conout->SetAttribute (conout, BOX_INPUT_TEXT); /* Make sure that the cursor appears */ conout->OutputString (conout, L""); } } goto get_input; default: if (count < (PASS_N_CHARS - 1)) { pass_buf[count] = input_key.UnicodeChar; if (count < PASS_FIELD_COLS) { conout->OutputString (conout, L"*"); } count++; } if (count + 1 != buf_nbytes) { goto get_input; } /* Fallthrough */ case 0x000A: case 0x000D: pass_buf[count + 1] = '\0'; *n_chars = count; break; } }
// // TDS 4.2.5 // EFI_STATUS BBTestSetAttributeConformanceAutoTest ( IN EFI_BB_TEST_PROTOCOL *This, IN VOID *ClientInterface, IN EFI_TEST_LEVEL TestLevel, IN EFI_HANDLE SupportHandle ) { // // This test case should be obsolete according to Spec changed. // EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib; EFI_STATUS Status; EFI_SIMPLE_TEXT_OUT_PROTOCOL *SimpleOut; EFI_TEST_ASSERTION AssertionType; EFI_SIMPLE_TEXT_OUTPUT_MODE ModeOrg, ModeExpected; UINTN Attribute[10]; UINTN Index; EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; EFI_DEVICE_PATH_PROTOCOL *DevicePath; CHAR16 *DevicePathStr; // // Get the Standard Library Interface // Status = gtBS->HandleProtocol ( SupportHandle, &gEfiStandardTestLibraryGuid, &StandardLib ); if (EFI_ERROR(Status)) { StandardLib->RecordAssertion ( StandardLib, EFI_TEST_ASSERTION_FAILED, gTestGenericFailureGuid, L"BS.HandleProtocol - Handle standard test library", L"%a:%d:Status - %r", __FILE__, (UINTN)__LINE__, Status ); return Status; } SimpleOut = (EFI_SIMPLE_TEXT_OUT_PROTOCOL *)ClientInterface; // // Get Device Path of current Simple_Text_Output_Protocol // And out put device path or device name // Status = LocateDevicePathFromSimpleTextOut (SimpleOut, &DevicePath, StandardLib); if (Status == EFI_SUCCESS) { DevicePathStr = DevicePathToStr (DevicePath); if (DevicePathStr != NULL) { StandardLib->RecordMessage ( StandardLib, EFI_VERBOSE_LEVEL_DEFAULT, L"\r\nCurrent Device: %s", DevicePathStr ); Status = gtBS->FreePool (DevicePathStr); if (EFI_ERROR(Status)) { StandardLib->RecordAssertion ( StandardLib, EFI_TEST_ASSERTION_FAILED, gTestGenericFailureGuid, L"BS.FreePool - Free pool", L"%a:%d:Status - %r", __FILE__, (UINTN)__LINE__, Status ); return Status; } DevicePathStr = NULL; } } else { Status = LocateGopFromSimpleTextOut (SimpleOut, &GraphicsOutput, StandardLib); if (EFI_ERROR(Status)) { // // Console Splitter/StdErr // StandardLib->RecordMessage ( StandardLib, EFI_VERBOSE_LEVEL_DEFAULT, L"\r\nCurrent Device: ConsoleSplitter/StdErr" ); } else { // // Console Splitter/ConOut // StandardLib->RecordMessage ( StandardLib, EFI_VERBOSE_LEVEL_DEFAULT, L"\r\nCurrent Device: ConsoleSplitter/ConOut" ); } } // // Prepare test data // Attribute[0] = 0xB3; Attribute[1] = 0x80; Attribute[2] = 0x91; Attribute[3] = 0xA2; Attribute[4] = 65538; // // Backup Mode // BackupMode (SimpleOut, &ModeOrg); for (Index = 0; Index < 5; Index++) { // // Prepare expected Mode after call Reset. // BackupMode (SimpleOut, &ModeExpected); // // Call SetAttribute with invalid Attribute // Status = SimpleOut->SetAttribute (SimpleOut, Attribute[Index]); // // Mode itegrity test // ModeExpected.CursorColumn = SimpleOut->Mode->CursorColumn; ModeExpected.CursorRow = SimpleOut->Mode->CursorRow; if (CheckModeIntegrity (&ModeExpected, SimpleOut->Mode) == FALSE) { AssertionType = EFI_TEST_ASSERTION_FAILED; } else { AssertionType = EFI_TEST_ASSERTION_PASSED; } StandardLib->RecordAssertion ( StandardLib, AssertionType, gSimpleTextOutputConformanceTestAssertionGuid005, L"EFI_SIMPLE_TEXT_OUT_PROTOCOL.SetAttribute - SetAttribute() with invalid Attribute, mode position integrity", L"%a:%d: Attribute=%x Current: Cursor Position(%d x %d), Mode=%d, MaxMode=%d, Attribute=%d, CursorVisible=%d. "\ L" Expected:Cursor Position(%d x %d), Mode=%d, MaxMode=%d, Attribute=%d, CursorVisible=%d.", __FILE__, (UINTN)__LINE__, Attribute[Index], SimpleOut->Mode->CursorColumn, SimpleOut->Mode->CursorRow, SimpleOut->Mode->Mode, SimpleOut->Mode->MaxMode, SimpleOut->Mode->Attribute, SimpleOut->Mode->CursorVisible, ModeExpected.CursorColumn, ModeExpected.CursorRow, ModeExpected.Mode, ModeExpected.MaxMode, ModeExpected.Attribute, ModeExpected.CursorVisible ); // // Status check // if (Status!=EFI_UNSUPPORTED) { AssertionType = EFI_TEST_ASSERTION_FAILED; } else { AssertionType = EFI_TEST_ASSERTION_PASSED; } StandardLib->RecordAssertion ( StandardLib, AssertionType, gSimpleTextOutputConformanceTestAssertionGuid006, L"EFI_SIMPLE_TEXT_OUT_PROTOCOL.SetAttribute - SetAttribute() with invalid Attribute", L"%a:%d: Status = %r, Attribute = %x", __FILE__, (UINTN)__LINE__, Status, Attribute[Index] ); } return RestoreMode (SimpleOut, &ModeOrg, StandardLib); }