X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FConsole%2FTerminalDxe%2FTerminalConIn.c;h=3c1102dac4a1e6db323d15a49f1f67f0db013514;hp=90bac164bce2a01e3a8e13a193ff4d83f81192a4;hb=3652f9902fc07c0d26bd1ce0492870b8de979809;hpb=59d88f42ca8b2d1556e52930a164f908814b9b9e diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c index 90bac164bc..3c1102dac4 100644 --- a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c +++ b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c @@ -1,7 +1,9 @@ /** @file Implementation for EFI_SIMPLE_TEXT_INPUT_PROTOCOL protocol. -Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
+(C) Copyright 2014 Hewlett-Packard Development Company, L.P.
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
+Copyright (C) 2016 Silicon Graphics, Inc. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -92,6 +94,7 @@ TerminalConInReset ( TerminalDevice->RawFiFo->Head = TerminalDevice->RawFiFo->Tail; TerminalDevice->UnicodeFiFo->Head = TerminalDevice->UnicodeFiFo->Tail; TerminalDevice->EfiKeyFiFo->Head = TerminalDevice->EfiKeyFiFo->Tail; + TerminalDevice->EfiKeyFiFoForNotify->Head = TerminalDevice->EfiKeyFiFoForNotify->Tail; if (EFI_ERROR (Status)) { REPORT_STATUS_CODE_WITH_DEVICE_PATH ( @@ -157,7 +160,7 @@ TerminalConInReadKeyStroke ( pressed. @retval TRUE Key be pressed matches a registered key. - @retval FLASE Match failed. + @retval FALSE Match failed. **/ BOOLEAN @@ -295,6 +298,10 @@ TerminalConInSetState ( return EFI_INVALID_PARAMETER; } + if ((*KeyToggleState & EFI_TOGGLE_STATE_VALID) != EFI_TOGGLE_STATE_VALID) { + return EFI_UNSUPPORTED; + } + return EFI_SUCCESS; } @@ -303,11 +310,14 @@ TerminalConInSetState ( Register a notification function for a particular keystroke for the input device. @param This Protocol instance pointer. - @param KeyData A pointer to a buffer that is filled in with the - keystroke information data for the key that was - pressed. + @param KeyData A pointer to a buffer that is filled in with + the keystroke information for the key that was + pressed. If KeyData.Key, KeyData.KeyState.KeyToggleState + and KeyData.KeyState.KeyShiftState are 0, then any incomplete + keystroke will trigger a notification of the KeyNotificationFunction. @param KeyNotificationFunction Points to the function to be called when the key - sequence is typed specified by KeyData. + sequence is typed specified by KeyData. This notification function + should be called at <=TPL_CALLBACK. @param NotifyHandle Points to the unique handle assigned to the registered notification. @@ -324,7 +334,7 @@ TerminalConInRegisterKeyNotify ( IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN EFI_KEY_DATA *KeyData, IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction, - OUT EFI_HANDLE *NotifyHandle + OUT VOID **NotifyHandle ) { TERMINAL_DEV *TerminalDevice; @@ -352,7 +362,7 @@ TerminalConInRegisterKeyNotify ( ); if (IsKeyRegistered (&CurrentNotify->KeyData, KeyData)) { if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) { - *NotifyHandle = CurrentNotify->NotifyHandle; + *NotifyHandle = CurrentNotify; return EFI_SUCCESS; } } @@ -368,11 +378,10 @@ TerminalConInRegisterKeyNotify ( NewNotify->Signature = TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE; NewNotify->KeyNotificationFn = KeyNotificationFunction; - NewNotify->NotifyHandle = (EFI_HANDLE) NewNotify; - CopyMem (&NewNotify->KeyData, KeyData, sizeof (KeyData)); + CopyMem (&NewNotify->KeyData, KeyData, sizeof (EFI_KEY_DATA)); InsertTailList (&TerminalDevice->NotifyList, &NewNotify->NotifyEntry); - *NotifyHandle = NewNotify->NotifyHandle; + *NotifyHandle = NewNotify; return EFI_SUCCESS; } @@ -394,7 +403,7 @@ EFI_STATUS EFIAPI TerminalConInUnregisterKeyNotify ( IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, - IN EFI_HANDLE NotificationHandle + IN VOID *NotificationHandle ) { TERMINAL_DEV *TerminalDevice; @@ -406,10 +415,6 @@ TerminalConInUnregisterKeyNotify ( return EFI_INVALID_PARAMETER; } - if (((TERMINAL_CONSOLE_IN_EX_NOTIFY *) NotificationHandle)->Signature != TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE) { - return EFI_INVALID_PARAMETER; - } - TerminalDevice = TERMINAL_CON_IN_EX_DEV_FROM_THIS (This); NotifyList = &TerminalDevice->NotifyList; @@ -420,7 +425,7 @@ TerminalConInUnregisterKeyNotify ( NotifyEntry, TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE ); - if (CurrentNotify->NotifyHandle == NotificationHandle) { + if (CurrentNotify == NotificationHandle) { // // Remove the notification function from NotifyList and free resources // @@ -451,14 +456,15 @@ TranslateRawDataToEfiKey ( { switch (TerminalDevice->TerminalType) { - case PCANSITYPE: - case VT100TYPE: - case VT100PLUSTYPE: + case TerminalTypePcAnsi: + case TerminalTypeVt100: + case TerminalTypeVt100Plus: + case TerminalTypeTtyTerm: AnsiRawDataToUnicode (TerminalDevice); UnicodeToEfiKey (TerminalDevice); break; - case VTUTF8TYPE: + case TerminalTypeVtUtf8: // // Process all the raw data in the RawFIFO, // put the processed key into UnicodeFIFO. @@ -561,10 +567,11 @@ TerminalConInTimerHandler ( } // // Check whether serial buffer is empty. + // Skip the key transfer loop only if the SerialIo protocol instance + // successfully reports EFI_SERIAL_INPUT_BUFFER_EMPTY. // Status = SerialIo->GetControl (SerialIo, &Control); - - if ((Control & EFI_SERIAL_INPUT_BUFFER_EMPTY) == 0) { + if (EFI_ERROR (Status) || ((Control & EFI_SERIAL_INPUT_BUFFER_EMPTY) == 0)) { // // Fetch all the keys in the serial buffer, // and insert the byte stream into RawFIFO. @@ -595,6 +602,59 @@ TerminalConInTimerHandler ( TranslateRawDataToEfiKey (TerminalDevice); } +/** + Process key notify. + + @param Event Indicates the event that invoke this function. + @param Context Indicates the calling context. +**/ +VOID +EFIAPI +KeyNotifyProcessHandler ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + BOOLEAN HasKey; + TERMINAL_DEV *TerminalDevice; + EFI_INPUT_KEY Key; + EFI_KEY_DATA KeyData; + LIST_ENTRY *Link; + LIST_ENTRY *NotifyList; + TERMINAL_CONSOLE_IN_EX_NOTIFY *CurrentNotify; + EFI_TPL OldTpl; + + TerminalDevice = (TERMINAL_DEV *) Context; + + // + // Invoke notification functions. + // + NotifyList = &TerminalDevice->NotifyList; + while (TRUE) { + // + // Enter critical section + // + OldTpl = gBS->RaiseTPL (TPL_NOTIFY); + HasKey = EfiKeyFiFoForNotifyRemoveOneKey (TerminalDevice->EfiKeyFiFoForNotify, &Key); + CopyMem (&KeyData.Key, &Key, sizeof (EFI_INPUT_KEY)); + KeyData.KeyState.KeyShiftState = 0; + KeyData.KeyState.KeyToggleState = 0; + // + // Leave critical section + // + gBS->RestoreTPL (OldTpl); + if (!HasKey) { + break; + } + for (Link = GetFirstNode (NotifyList); !IsNull (NotifyList, Link); Link = GetNextNode (NotifyList, Link)) { + CurrentNotify = CR (Link, TERMINAL_CONSOLE_IN_EX_NOTIFY, NotifyEntry, TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE); + if (IsKeyRegistered (&CurrentNotify->KeyData, &KeyData)) { + CurrentNotify->KeyNotificationFn (&KeyData); + } + } + } +} + /** Get one key out of serial buffer. @@ -648,7 +708,7 @@ GetOneKeyFromSerial ( @param Input The key will be input. @retval TRUE If insert successfully. - @retval FLASE If Raw Data buffer is full before key insertion, + @retval FALSE If Raw Data buffer is full before key insertion, and the key is lost. **/ @@ -683,7 +743,7 @@ RawFiFoInsertOneKey ( @param Output The key will be removed. @retval TRUE If insert successfully. - @retval FLASE If Raw Data FIFO buffer is empty before remove operation. + @retval FALSE If Raw Data FIFO buffer is empty before remove operation. **/ BOOLEAN @@ -717,7 +777,7 @@ RawFiFoRemoveOneKey ( @param TerminalDevice Terminal driver private structure @retval TRUE If Raw Data FIFO buffer is empty. - @retval FLASE If Raw Data FIFO buffer is not empty. + @retval FALSE If Raw Data FIFO buffer is not empty. **/ BOOLEAN @@ -738,7 +798,7 @@ IsRawFiFoEmpty ( @param TerminalDevice Terminal driver private structure @retval TRUE If Raw Data FIFO buffer is full. - @retval FLASE If Raw Data FIFO buffer is not full. + @retval FALSE If Raw Data FIFO buffer is not full. **/ BOOLEAN @@ -760,6 +820,126 @@ IsRawFiFoFull ( return FALSE; } +/** + Insert one pre-fetched key into the FIFO buffer. + + @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO. + @param Input The key will be input. + + @retval TRUE If insert successfully. + @retval FALSE If FIFO buffer is full before key insertion, + and the key is lost. + +**/ +BOOLEAN +EfiKeyFiFoForNotifyInsertOneKey ( + EFI_KEY_FIFO *EfiKeyFiFo, + EFI_INPUT_KEY *Input + ) +{ + UINT8 Tail; + + Tail = EfiKeyFiFo->Tail; + + if (IsEfiKeyFiFoForNotifyFull (EfiKeyFiFo)) { + // + // FIFO is full + // + return FALSE; + } + + CopyMem (&EfiKeyFiFo->Data[Tail], Input, sizeof (EFI_INPUT_KEY)); + + EfiKeyFiFo->Tail = (UINT8) ((Tail + 1) % (FIFO_MAX_NUMBER + 1)); + + return TRUE; +} + +/** + Remove one pre-fetched key out of the FIFO buffer. + + @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO. + @param Output The key will be removed. + + @retval TRUE If remove successfully. + @retval FALSE If FIFO buffer is empty before remove operation. + +**/ +BOOLEAN +EfiKeyFiFoForNotifyRemoveOneKey ( + EFI_KEY_FIFO *EfiKeyFiFo, + EFI_INPUT_KEY *Output + ) +{ + UINT8 Head; + + Head = EfiKeyFiFo->Head; + ASSERT (Head < FIFO_MAX_NUMBER + 1); + + if (IsEfiKeyFiFoForNotifyEmpty (EfiKeyFiFo)) { + // + // FIFO is empty + // + Output->ScanCode = SCAN_NULL; + Output->UnicodeChar = 0; + return FALSE; + } + + CopyMem (Output, &EfiKeyFiFo->Data[Head], sizeof (EFI_INPUT_KEY)); + + EfiKeyFiFo->Head = (UINT8) ((Head + 1) % (FIFO_MAX_NUMBER + 1)); + + return TRUE; +} + +/** + Clarify whether FIFO buffer is empty. + + @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO. + + @retval TRUE If FIFO buffer is empty. + @retval FALSE If FIFO buffer is not empty. + +**/ +BOOLEAN +IsEfiKeyFiFoForNotifyEmpty ( + EFI_KEY_FIFO *EfiKeyFiFo + ) +{ + if (EfiKeyFiFo->Head == EfiKeyFiFo->Tail) { + return TRUE; + } else { + return FALSE; + } +} + +/** + Clarify whether FIFO buffer is full. + + @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO. + + @retval TRUE If FIFO buffer is full. + @retval FALSE If FIFO buffer is not full. + +**/ +BOOLEAN +IsEfiKeyFiFoForNotifyFull ( + EFI_KEY_FIFO *EfiKeyFiFo + ) +{ + UINT8 Tail; + UINT8 Head; + + Tail = EfiKeyFiFo->Tail; + Head = EfiKeyFiFo->Head; + + if (((Tail + 1) % (FIFO_MAX_NUMBER + 1)) == Head) { + return TRUE; + } + + return FALSE; +} + /** Insert one pre-fetched key into the FIFO buffer. @@ -767,7 +947,7 @@ IsRawFiFoFull ( @param Key The key will be input. @retval TRUE If insert successfully. - @retval FLASE If FIFO buffer is full before key insertion, + @retval FALSE If FIFO buffer is full before key insertion, and the key is lost. **/ @@ -790,7 +970,7 @@ EfiKeyFiFoInsertOneKey ( KeyData.KeyState.KeyToggleState = 0; // - // Invoke notification functions if exist + // Signal KeyNotify process event if this key pressed matches any key registered. // NotifyList = &TerminalDevice->NotifyList; for (Link = GetFirstNode (NotifyList); !IsNull (NotifyList,Link); Link = GetNextNode (NotifyList,Link)) { @@ -801,7 +981,13 @@ EfiKeyFiFoInsertOneKey ( TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE ); if (IsKeyRegistered (&CurrentNotify->KeyData, &KeyData)) { - CurrentNotify->KeyNotificationFn (&KeyData); + // + // The key notification function needs to run at TPL_CALLBACK + // while current TPL is TPL_NOTIFY. It will be invoked in + // KeyNotifyProcessHandler() which runs at TPL_CALLBACK. + // + EfiKeyFiFoForNotifyInsertOneKey (TerminalDevice->EfiKeyFiFoForNotify, Key); + gBS->SignalEvent (TerminalDevice->KeyNotifyProcessEvent); } } if (IsEfiKeyFiFoFull (TerminalDevice)) { @@ -825,7 +1011,7 @@ EfiKeyFiFoInsertOneKey ( @param Output The key will be removed. @retval TRUE If insert successfully. - @retval FLASE If FIFO buffer is empty before remove operation. + @retval FALSE If FIFO buffer is empty before remove operation. **/ BOOLEAN @@ -848,7 +1034,7 @@ EfiKeyFiFoRemoveOneKey ( return FALSE; } - *Output = TerminalDevice->EfiKeyFiFo->Data[Head]; + CopyMem (Output, &TerminalDevice->EfiKeyFiFo->Data[Head], sizeof (EFI_INPUT_KEY)); TerminalDevice->EfiKeyFiFo->Head = (UINT8) ((Head + 1) % (FIFO_MAX_NUMBER + 1)); @@ -861,7 +1047,7 @@ EfiKeyFiFoRemoveOneKey ( @param TerminalDevice Terminal driver private structure @retval TRUE If FIFO buffer is empty. - @retval FLASE If FIFO buffer is not empty. + @retval FALSE If FIFO buffer is not empty. **/ BOOLEAN @@ -882,7 +1068,7 @@ IsEfiKeyFiFoEmpty ( @param TerminalDevice Terminal driver private structure @retval TRUE If FIFO buffer is full. - @retval FLASE If FIFO buffer is not full. + @retval FALSE If FIFO buffer is not full. **/ BOOLEAN @@ -911,7 +1097,7 @@ IsEfiKeyFiFoFull ( @param Input The key will be input. @retval TRUE If insert successfully. - @retval FLASE If Unicode FIFO buffer is full before key insertion, + @retval FALSE If Unicode FIFO buffer is full before key insertion, and the key is lost. **/ @@ -943,15 +1129,14 @@ UnicodeFiFoInsertOneKey ( /** Remove one pre-fetched key out of the Unicode FIFO buffer. + The caller should guarantee that Unicode FIFO buffer is not empty + by IsUnicodeFiFoEmpty (). @param TerminalDevice Terminal driver private structure. @param Output The key will be removed. - @retval TRUE If insert successfully. - @retval FLASE If Unicode FIFO buffer is empty before remove operation. - **/ -BOOLEAN +VOID UnicodeFiFoRemoveOneKey ( TERMINAL_DEV *TerminalDevice, UINT16 *Output @@ -962,19 +1147,9 @@ UnicodeFiFoRemoveOneKey ( Head = TerminalDevice->UnicodeFiFo->Head; ASSERT (Head < FIFO_MAX_NUMBER + 1); - if (IsUnicodeFiFoEmpty (TerminalDevice)) { - // - // FIFO is empty - // - Output = NULL; - return FALSE; - } - *Output = TerminalDevice->UnicodeFiFo->Data[Head]; TerminalDevice->UnicodeFiFo->Head = (UINT8) ((Head + 1) % (FIFO_MAX_NUMBER + 1)); - - return TRUE; } /** @@ -983,7 +1158,7 @@ UnicodeFiFoRemoveOneKey ( @param TerminalDevice Terminal driver private structure @retval TRUE If Unicode FIFO buffer is empty. - @retval FLASE If Unicode FIFO buffer is not empty. + @retval FALSE If Unicode FIFO buffer is not empty. **/ BOOLEAN @@ -1004,7 +1179,7 @@ IsUnicodeFiFoEmpty ( @param TerminalDevice Terminal driver private structure @retval TRUE If Unicode FIFO buffer is full. - @retval FLASE If Unicode FIFO buffer is not full. + @retval FALSE If Unicode FIFO buffer is not full. **/ BOOLEAN @@ -1233,7 +1408,8 @@ UnicodeToEfiKey ( continue; } - if (UnicodeChar == 'O' && TerminalDevice->TerminalType == VT100TYPE) { + if (UnicodeChar == 'O' && (TerminalDevice->TerminalType == TerminalTypeVt100 || + TerminalDevice->TerminalType == TerminalTypeTtyTerm)) { TerminalDevice->InputState |= INPUT_STATE_O; TerminalDevice->ResetState = RESET_STATE_DEFAULT; continue; @@ -1241,8 +1417,8 @@ UnicodeToEfiKey ( Key.ScanCode = SCAN_NULL; - if (TerminalDevice->TerminalType == VT100PLUSTYPE || - TerminalDevice->TerminalType == VTUTF8TYPE) { + if (TerminalDevice->TerminalType == TerminalTypeVt100Plus || + TerminalDevice->TerminalType == TerminalTypeVtUtf8) { switch (UnicodeChar) { case '1': Key.ScanCode = SCAN_F1; @@ -1346,7 +1522,7 @@ UnicodeToEfiKey ( Key.ScanCode = SCAN_NULL; - if (TerminalDevice->TerminalType == VT100TYPE) { + if (TerminalDevice->TerminalType == TerminalTypeVt100) { switch (UnicodeChar) { case 'P': Key.ScanCode = SCAN_F1; @@ -1381,6 +1557,28 @@ UnicodeToEfiKey ( default : break; } + } else if (TerminalDevice->TerminalType == TerminalTypeTtyTerm) { + /* Also accept VT100 escape codes for F1-F4, HOME and END for TTY term */ + switch (UnicodeChar) { + case 'P': + Key.ScanCode = SCAN_F1; + break; + case 'Q': + Key.ScanCode = SCAN_F2; + break; + case 'R': + Key.ScanCode = SCAN_F3; + break; + case 'S': + Key.ScanCode = SCAN_F4; + break; + case 'H': + Key.ScanCode = SCAN_HOME; + break; + case 'F': + Key.ScanCode = SCAN_END; + break; + } } if (Key.ScanCode != SCAN_NULL) { @@ -1401,10 +1599,11 @@ UnicodeToEfiKey ( Key.ScanCode = SCAN_NULL; - if (TerminalDevice->TerminalType == PCANSITYPE || - TerminalDevice->TerminalType == VT100TYPE || - TerminalDevice->TerminalType == VT100PLUSTYPE || - TerminalDevice->TerminalType == VTUTF8TYPE) { + if (TerminalDevice->TerminalType == TerminalTypePcAnsi || + TerminalDevice->TerminalType == TerminalTypeVt100 || + TerminalDevice->TerminalType == TerminalTypeVt100Plus || + TerminalDevice->TerminalType == TerminalTypeVtUtf8 || + TerminalDevice->TerminalType == TerminalTypeTtyTerm) { switch (UnicodeChar) { case 'A': Key.ScanCode = SCAN_UP; @@ -1419,100 +1618,104 @@ UnicodeToEfiKey ( Key.ScanCode = SCAN_LEFT; break; case 'H': - if (TerminalDevice->TerminalType == PCANSITYPE || - TerminalDevice->TerminalType == VT100TYPE) { + if (TerminalDevice->TerminalType == TerminalTypePcAnsi || + TerminalDevice->TerminalType == TerminalTypeVt100 || + TerminalDevice->TerminalType == TerminalTypeTtyTerm) { Key.ScanCode = SCAN_HOME; } break; case 'F': - if (TerminalDevice->TerminalType == PCANSITYPE) { + if (TerminalDevice->TerminalType == TerminalTypePcAnsi || + TerminalDevice->TerminalType == TerminalTypeTtyTerm) { Key.ScanCode = SCAN_END; } break; case 'K': - if (TerminalDevice->TerminalType == VT100TYPE) { + if (TerminalDevice->TerminalType == TerminalTypeVt100) { Key.ScanCode = SCAN_END; } break; case 'L': case '@': - if (TerminalDevice->TerminalType == PCANSITYPE || - TerminalDevice->TerminalType == VT100TYPE) { + if (TerminalDevice->TerminalType == TerminalTypePcAnsi || + TerminalDevice->TerminalType == TerminalTypeVt100) { Key.ScanCode = SCAN_INSERT; } break; case 'X': - if (TerminalDevice->TerminalType == PCANSITYPE) { + if (TerminalDevice->TerminalType == TerminalTypePcAnsi) { Key.ScanCode = SCAN_DELETE; } break; case 'P': - if (TerminalDevice->TerminalType == VT100TYPE) { + if (TerminalDevice->TerminalType == TerminalTypeVt100) { Key.ScanCode = SCAN_DELETE; - } else if (TerminalDevice->TerminalType == PCANSITYPE) { + } else if (TerminalDevice->TerminalType == TerminalTypePcAnsi) { Key.ScanCode = SCAN_F4; } break; case 'I': - if (TerminalDevice->TerminalType == PCANSITYPE) { + if (TerminalDevice->TerminalType == TerminalTypePcAnsi) { Key.ScanCode = SCAN_PAGE_UP; } break; case 'V': - if (TerminalDevice->TerminalType == PCANSITYPE) { + if (TerminalDevice->TerminalType == TerminalTypePcAnsi) { Key.ScanCode = SCAN_F10; } + break; case '?': - if (TerminalDevice->TerminalType == VT100TYPE) { + if (TerminalDevice->TerminalType == TerminalTypeVt100) { Key.ScanCode = SCAN_PAGE_UP; } break; case 'G': - if (TerminalDevice->TerminalType == PCANSITYPE) { + if (TerminalDevice->TerminalType == TerminalTypePcAnsi) { Key.ScanCode = SCAN_PAGE_DOWN; } break; case 'U': - if (TerminalDevice->TerminalType == PCANSITYPE) { + if (TerminalDevice->TerminalType == TerminalTypePcAnsi) { Key.ScanCode = SCAN_F9; } + break; case '/': - if (TerminalDevice->TerminalType == VT100TYPE) { + if (TerminalDevice->TerminalType == TerminalTypeVt100) { Key.ScanCode = SCAN_PAGE_DOWN; } break; case 'M': - if (TerminalDevice->TerminalType == PCANSITYPE) { + if (TerminalDevice->TerminalType == TerminalTypePcAnsi) { Key.ScanCode = SCAN_F1; } break; case 'N': - if (TerminalDevice->TerminalType == PCANSITYPE) { + if (TerminalDevice->TerminalType == TerminalTypePcAnsi) { Key.ScanCode = SCAN_F2; } break; case 'O': - if (TerminalDevice->TerminalType == PCANSITYPE) { + if (TerminalDevice->TerminalType == TerminalTypePcAnsi) { Key.ScanCode = SCAN_F3; } break; case 'Q': - if (TerminalDevice->TerminalType == PCANSITYPE) { + if (TerminalDevice->TerminalType == TerminalTypePcAnsi) { Key.ScanCode = SCAN_F5; } break; case 'R': - if (TerminalDevice->TerminalType == PCANSITYPE) { + if (TerminalDevice->TerminalType == TerminalTypePcAnsi) { Key.ScanCode = SCAN_F6; } break; case 'S': - if (TerminalDevice->TerminalType == PCANSITYPE) { + if (TerminalDevice->TerminalType == TerminalTypePcAnsi) { Key.ScanCode = SCAN_F7; } break; case 'T': - if (TerminalDevice->TerminalType == PCANSITYPE) { + if (TerminalDevice->TerminalType == TerminalTypePcAnsi) { Key.ScanCode = SCAN_F8; } break; @@ -1521,6 +1724,21 @@ UnicodeToEfiKey ( } } + /* + * The VT220 escape codes that the TTY terminal accepts all have + * numeric codes, and there are no ambiguous prefixes shared with + * other terminal types. + */ + if (TerminalDevice->TerminalType == TerminalTypeTtyTerm && + Key.ScanCode == SCAN_NULL && + UnicodeChar >= '0' && + UnicodeChar <= '9') { + TerminalDevice->TtyEscapeStr[0] = UnicodeChar; + TerminalDevice->TtyEscapeIndex = 1; + TerminalDevice->InputState |= INPUT_STATE_LEFTOPENBRACKET_2; + continue; + } + if (Key.ScanCode != SCAN_NULL) { Key.UnicodeChar = 0; EfiKeyFiFoInsertOneKey (TerminalDevice, &Key); @@ -1534,6 +1752,74 @@ UnicodeToEfiKey ( break; + case INPUT_STATE_ESC | INPUT_STATE_LEFTOPENBRACKET | INPUT_STATE_LEFTOPENBRACKET_2: + /* + * Here we handle the VT220 escape codes that we accept. This + * state is only used by the TTY terminal type. + */ + Key.ScanCode = SCAN_NULL; + if (TerminalDevice->TerminalType == TerminalTypeTtyTerm) { + + if (UnicodeChar == '~' && TerminalDevice->TtyEscapeIndex <= 2) { + UINT16 EscCode; + TerminalDevice->TtyEscapeStr[TerminalDevice->TtyEscapeIndex] = 0; /* Terminate string */ + EscCode = (UINT16) StrDecimalToUintn(TerminalDevice->TtyEscapeStr); + switch (EscCode) { + case 2: + Key.ScanCode = SCAN_INSERT; + break; + case 3: + Key.ScanCode = SCAN_DELETE; + break; + case 5: + Key.ScanCode = SCAN_PAGE_UP; + break; + case 6: + Key.ScanCode = SCAN_PAGE_DOWN; + break; + case 11: + case 12: + case 13: + case 14: + case 15: + Key.ScanCode = SCAN_F1 + EscCode - 11; + break; + case 17: + case 18: + case 19: + case 20: + case 21: + Key.ScanCode = SCAN_F6 + EscCode - 17; + break; + case 23: + case 24: + Key.ScanCode = SCAN_F11 + EscCode - 23; + break; + default: + break; + } + } else if (TerminalDevice->TtyEscapeIndex == 1){ + /* 2 character escape code */ + TerminalDevice->TtyEscapeStr[TerminalDevice->TtyEscapeIndex++] = UnicodeChar; + continue; + } + else { + DEBUG ((EFI_D_ERROR, "Unexpected state in escape2\n")); + } + } + TerminalDevice->ResetState = RESET_STATE_DEFAULT; + + if (Key.ScanCode != SCAN_NULL) { + Key.UnicodeChar = 0; + EfiKeyFiFoInsertOneKey (TerminalDevice, &Key); + TerminalDevice->InputState = INPUT_STATE_DEFAULT; + UnicodeToEfiKeyFlushState (TerminalDevice); + continue; + } + + UnicodeToEfiKeyFlushState (TerminalDevice); + break; + default: // // Invalid state. This should never happen. @@ -1568,8 +1854,14 @@ UnicodeToEfiKey ( } if (UnicodeChar == DEL) { - Key.ScanCode = SCAN_DELETE; - Key.UnicodeChar = 0; + if (TerminalDevice->TerminalType == TerminalTypeTtyTerm) { + Key.ScanCode = SCAN_NULL; + Key.UnicodeChar = CHAR_BACKSPACE; + } + else { + Key.ScanCode = SCAN_DELETE; + Key.UnicodeChar = 0; + } } else { Key.ScanCode = SCAN_NULL; Key.UnicodeChar = UnicodeChar;