From patchwork Mon Jul 6 23:04:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 50798 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 66527229FC for ; Mon, 6 Jul 2015 23:05:21 +0000 (UTC) Received: by wifm2 with SMTP id m2sf15027262wif.1 for ; Mon, 06 Jul 2015 16:05:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:reply-to:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:errors-to:x-original-sender :x-original-authentication-results:mailing-list; bh=QSyGDccRL1rkaleAEJOk45gV2EO4hMc06KZbQ/OlD30=; b=TTPz0ZaEb5KsHUR9kjxqVc0kPzhSAsXtPQf7a3j/nI/LMsj0OvwS5jKcwtVpFBl6L5 IOz2INflWJpuxFo2Etuvp7Pw9cywdWenAard8AYkMNZ9SAggDe78UDECIuDSZtQ2/pJO J/YdGiPz2Gf30mtPjfatJS38EFI1ZuQrHij7pVEi9wP6/HEsWpjWiJGvcaDJhNnRZs3R uXEKcdhD9FNl1h9FlpSMVJG0NuYEGanE+8lMyqo4IdhrPz+fMbdP3xIe4Gr5WxGZlYeT GbWoqqRoD4CwuudlQgF/38htx0ddTZDnMYzYJ/5hQ762nMzrg8NMihRyysW6mbglwpIU KFEg== X-Gm-Message-State: ALoCoQnu3r3sSLWIYGROEcGcaaQgJFLBc8mNCTSzCjp8++4s3OeDUngWjfPOldNKtBJHS/wyUVGB X-Received: by 10.152.22.71 with SMTP id b7mr586817laf.3.1436223920711; Mon, 06 Jul 2015 16:05:20 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.69 with SMTP id w5ls761846laj.107.gmail; Mon, 06 Jul 2015 16:05:20 -0700 (PDT) X-Received: by 10.152.88.6 with SMTP id bc6mr1144250lab.23.1436223920432; Mon, 06 Jul 2015 16:05:20 -0700 (PDT) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id jm1si16480435lbc.84.2015.07.06.16.05.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jul 2015 16:05:20 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by laar3 with SMTP id r3so174219999laa.0 for ; Mon, 06 Jul 2015 16:05:20 -0700 (PDT) X-Received: by 10.112.166.2 with SMTP id zc2mr1137405lbb.29.1436223920329; Mon, 06 Jul 2015 16:05:20 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp2009591lbb; Mon, 6 Jul 2015 16:05:19 -0700 (PDT) X-Received: by 10.50.134.196 with SMTP id pm4mr70878137igb.6.1436223917030; Mon, 06 Jul 2015 16:05:17 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id a3si18498525icv.24.2015.07.06.16.05.16 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 06 Jul 2015 16:05:17 -0700 (PDT) Received-SPF: pass (google.com: domain of edk2-devel-bounces@lists.sourceforge.net designates 216.34.181.88 as permitted sender) client-ip=216.34.181.88; Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ZCFRi-0006AQ-Tf; Mon, 06 Jul 2015 23:05:06 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ZCFRh-0006AK-Of for edk2-devel@lists.sourceforge.net; Mon, 06 Jul 2015 23:05:05 +0000 Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of linaro.org designates 209.85.192.182 as permitted sender) client-ip=209.85.192.182; envelope-from=roy.franz@linaro.org; helo=mail-pd0-f182.google.com; Received: from mail-pd0-f182.google.com ([209.85.192.182]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1ZCFRg-0003KQ-MD for edk2-devel@lists.sourceforge.net; Mon, 06 Jul 2015 23:05:05 +0000 Received: by pdbep18 with SMTP id ep18so113501815pdb.1 for ; Mon, 06 Jul 2015 16:04:59 -0700 (PDT) X-Received: by 10.70.20.5 with SMTP id j5mr2374964pde.40.1436223899017; Mon, 06 Jul 2015 16:04:59 -0700 (PDT) Received: from localhost.localdomain (c-73-41-93-56.hsd1.ca.comcast.net. [73.41.93.56]) by mx.google.com with ESMTPSA id m2sm19544337pdp.4.2015.07.06.16.04.57 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Jul 2015 16:04:57 -0700 (PDT) From: Roy Franz To: edk2-devel@lists.sourceforge.net, feng.tian@intel.com, lersek@redhat.com, ard.biesheuvel@linaro.org Date: Mon, 6 Jul 2015 16:04:38 -0700 Message-Id: <1436223879-27956-4-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1436223879-27956-1-git-send-email-roy.franz@linaro.org> References: <1436223879-27956-1-git-send-email-roy.franz@linaro.org> X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record -0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1ZCFRg-0003KQ-MD Subject: [edk2] [PATCH V2 3/4] Accept VT220 DEL and function keys for TTY terminal type X-BeenThere: edk2-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: edk2-devel@lists.sourceforge.net List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.sourceforge.net X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: roy.franz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Accept the VT220 escape code [3~ as backspace for TtyTerm terminals. This is sent by many Linux terminals by default. Also accept VT220 function keys F1-F12, and VT100 F1-F4 keys as these are commonly sent by Linux terminals. The VT220 escape codes are longer, and variable length so a new state is added to the state machine along with a variable to construct the multibyte escape sequence. There are currently no ambiguous escape sequence prefixes accepted, so the TTY terminal accepts escape sequences for a variety of terminals. The goal is to 'just work' with as many terminals as possible, rather than properly emulating any specific terminal. Backspace, Del, and F10 have been tested on xterm, rxvt, tmux, and screen. Note: The existing vt100 function key handling does not match the vt100 documentation that I found, so I added the TTY terminal handling of VT100 F1-F4 (really PF1-PF4 on vt100) separately. The vt100 has no F5-F10 keys, so I don't know what the current vt100 code is based on. Signed-off-by: Roy Franz Contributed-under: TianoCore Contribution Agreement 1.0 Reviewed-by: Ard Biesheuvel --- MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h | 1 + MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c | 95 +++++++++++++++++++- 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h index 03542a4..4616ab3 100644 --- a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h +++ b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h @@ -118,6 +118,7 @@ typedef struct { #define INPUT_STATE_LEFTOPENBRACKET 0x04 #define INPUT_STATE_O 0x08 #define INPUT_STATE_2 0x10 +#define INPUT_STATE_LEFTOPENBRACKET_2 0x20 #define RESET_STATE_DEFAULT 0x00 #define RESET_STATE_ESC_R 0x01 diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c index 227df85..12e7f9f 100644 --- a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c +++ b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c @@ -1182,6 +1182,8 @@ UnicodeToEfiKey ( UINT16 UnicodeChar; EFI_INPUT_KEY Key; BOOLEAN SetDefaultResetState; + static UINT16 TtyEscapeStr[3]; + static INTN TtyEscapeIndex; TimerStatus = gBS->CheckEvent (TerminalDevice->TwoSecondTimeOut); @@ -1223,7 +1225,8 @@ UnicodeToEfiKey ( continue; } - if (UnicodeChar == 'O' && TerminalDevice->TerminalType == VT100TYPE) { + if (UnicodeChar == 'O' && (TerminalDevice->TerminalType == VT100TYPE || + TerminalDevice->TerminalType == TTYTERMTYPE)) { TerminalDevice->InputState |= INPUT_STATE_O; TerminalDevice->ResetState = RESET_STATE_DEFAULT; continue; @@ -1371,6 +1374,22 @@ UnicodeToEfiKey ( default : break; } + } else if (TerminalDevice->TerminalType == TTYTERMTYPE) { + /* Also accept VT100 escape codes for F1-F4 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; + } } if (Key.ScanCode != SCAN_NULL) { @@ -1514,6 +1533,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 == TTYTERMTYPE && + Key.ScanCode == SCAN_NULL && + UnicodeChar >= '0' && + UnicodeChar <= '9') { + TtyEscapeStr[0] = UnicodeChar; + TtyEscapeIndex = 1; + TerminalDevice->InputState |= INPUT_STATE_LEFTOPENBRACKET_2; + continue; + } + if (Key.ScanCode != SCAN_NULL) { Key.UnicodeChar = 0; EfiKeyFiFoInsertOneKey (TerminalDevice, &Key); @@ -1527,6 +1561,65 @@ 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 == TTYTERMTYPE) { + + if (UnicodeChar == '~' && TtyEscapeIndex <= 2) { + UINTN EscCode; + TtyEscapeStr[TtyEscapeIndex] = 0; /* Terminate string */ + EscCode = StrDecimalToUintn(TtyEscapeStr); + switch (EscCode) { + case 3: + Key.ScanCode = SCAN_DELETE; + 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 (TtyEscapeIndex == 1){ + /* 2 character escape code */ + TtyEscapeStr[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.