From nobody Wed Nov 23 09:44:06 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NHGRV4cFvz4jCsZ; Wed, 23 Nov 2022 09:44:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NHGRV48R3z4FyM; Wed, 23 Nov 2022 09:44:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669196646; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=68BT5+1/Hz6RxWYeMZ6XIEeVTmhENigvtGxM2RyMvLI=; b=CxTz5pF0BeLHqfG+jFsXpPK1QfPi1pvWDWy31/tLSsh/PiDd8v+P5htAuOFu/XzaUgNa1/ /Mx8be9WBl50h68RcYH97/bTFyLH3EH0Q0mI0MMWfRKetYWnes/ixAJWUmGNVCs596sPGu QKlBFTSZDbrqGdjZlhsNmdnDj53sGmjVvPnsyGmVfqr99lbzCLxE0t0EMEDq1SJCbYynLP E72Z8CiIUZ/+w+5rwR5LVOW5eeSQ1VvPkGS3yHcNizy/9wcWIjcVzy4EkrMiZ8a+iAuAj3 v4WqAnSCLnuSgsdb4egc4aDd6SqT+aCweFpdTLo98lhsidB7Ty09jy0Bl5qELQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669196646; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=68BT5+1/Hz6RxWYeMZ6XIEeVTmhENigvtGxM2RyMvLI=; b=v0I7UdHmnCC+qFHX7deL9VVqmuNwddU7iGY3bXy+db4Nplbxjp2zoVV24q6vKrEJJED4fe EWlsLQAvVc8qAjcrM8usO2J3r8TjO61G2FEsy6rF+9lbmMc8oEtVm+A7i7ZNxL6GC5XPUX 3NkvyrAkR1jXjVQ6SLkV8DAGOPY/+fya19JuNfq2cNYrxkfiAG1A+gYcVkZVavH9im9cgs QtT422qk8jmxsdya2PtwIHI50DZ4XkkAqK+eG47Eaoug2IqQBQSCJ43mpP5QrUcJX4TPxv KQwkUu9BHcH8W6chHUTG99H3WnujAc1QAJw3di1jfStuSttEMDn8bhOZbapCBQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1669196646; a=rsa-sha256; cv=none; b=bEqMD0m/sqElquo7d1eEbnD9y/Eb86dv7GMR9QqMEOZOgYK5pdwkau4FWK+sGiiQiYH2m8 co5FsArRGnOEMQBfl/5q0SwicZpM5yk7J+XNPlRx15E1vYVNhb+02QTAJiID4/QnBMxFOa QdTLV/lVB3H8CejB7xWonVeNioKfm6NedMwrtHeJRN5MzuF4w8pNF0pbfiEVFK9K1Si0WK 4xIXL315p//M78yrH7krvwzgCcJNjvSxsbXV8m/GUkBZ9QnOkUn0dCTJcjR6sGsCDglL8/ yHyIf0Nh8uYkAE86SlfNNnD6q2Wk9JWNo0E7Av4Sgl93fPZz2B/lv90GaG8Mcw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NHGRV3G8HzJDb; Wed, 23 Nov 2022 09:44:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2AN9i620015827; Wed, 23 Nov 2022 09:44:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AN9i698015826; Wed, 23 Nov 2022 09:44:06 GMT (envelope-from git) Date: Wed, 23 Nov 2022 09:44:06 GMT Message-Id: <202211230944.2AN9i698015826@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: =?utf-8?Q?Corvin=20K=C3=B6hne?= Subject: git: 7c85b2342aa2 - stable/13 - Append Keyboard Layout specified option for using VNC. Part one: supporting QEMU Extended Keyboard Event Message List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: corvink X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 7c85b2342aa2f737ed7c81a83dc510db8f7e172d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=7c85b2342aa2f737ed7c81a83dc510db8f7e172d commit 7c85b2342aa2f737ed7c81a83dc510db8f7e172d Author: Michael Reifenberger AuthorDate: 2021-04-21 10:38:26 +0000 Commit: Corvin Köhne CommitDate: 2022-11-23 09:11:44 +0000 Append Keyboard Layout specified option for using VNC. Part one: supporting QEMU Extended Keyboard Event Message PR: 246121 Submitted by: koinec@yahoo.co.jp Differential Revision: https://reviews.freebsd.org/D29430 (cherry picked from commit b563ff5d4f812df198ade6991834782a5d35af08) --- usr.sbin/bhyve/console.c | 4 +-- usr.sbin/bhyve/console.h | 4 +-- usr.sbin/bhyve/ps2kbd.c | 54 ++++++++++++++++++++++++++---------- usr.sbin/bhyve/rfb.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 115 insertions(+), 19 deletions(-) diff --git a/usr.sbin/bhyve/console.c b/usr.sbin/bhyve/console.c index 2567f699595c..d845df754048 100644 --- a/usr.sbin/bhyve/console.c +++ b/usr.sbin/bhyve/console.c @@ -106,10 +106,10 @@ console_ptr_register(ptr_event_func_t event_cb, void *arg, int pri) } void -console_key_event(int down, uint32_t keysym) +console_key_event(int down, uint32_t keysym, uint32_t keycode) { if (console.kbd_event_cb) - (*console.kbd_event_cb)(down, keysym, console.kbd_arg); + (*console.kbd_event_cb)(down, keysym, keycode, console.kbd_arg); } void diff --git a/usr.sbin/bhyve/console.h b/usr.sbin/bhyve/console.h index 0d0a85486625..8029c28ab8a9 100644 --- a/usr.sbin/bhyve/console.h +++ b/usr.sbin/bhyve/console.h @@ -34,7 +34,7 @@ struct bhyvegc; typedef void (*fb_render_func_t)(struct bhyvegc *gc, void *arg); -typedef void (*kbd_event_func_t)(int down, uint32_t keysym, void *arg); +typedef void (*kbd_event_func_t)(int down, uint32_t keysym, uint32_t keycode, void *arg); typedef void (*ptr_event_func_t)(uint8_t mask, int x, int y, void *arg); void console_init(int w, int h, void *fbaddr); @@ -47,7 +47,7 @@ void console_fb_register(fb_render_func_t render_cb, void *arg); void console_refresh(void); void console_kbd_register(kbd_event_func_t event_cb, void *arg, int pri); -void console_key_event(int down, uint32_t keysym); +void console_key_event(int down, uint32_t keysym, uint32_t keycode); void console_ptr_register(ptr_event_func_t event_cb, void *arg, int pri); void console_ptr_event(uint8_t button, int x, int y); diff --git a/usr.sbin/bhyve/ps2kbd.c b/usr.sbin/bhyve/ps2kbd.c index ef20fa47e0a9..012c66160ebe 100644 --- a/usr.sbin/bhyve/ps2kbd.c +++ b/usr.sbin/bhyve/ps2kbd.c @@ -181,6 +181,26 @@ static const uint8_t ascii_translations[128] = { 0x22, 0x35, 0x1a, 0x54, 0x5d, 0x5b, 0x0e, 0x00, }; +/* ScanCode set1 to set2 lookup table */ +const uint8_t keyset1to2_translations[128] = { + 0, 0x76, 0x16, 0x1E, 0x26, 0x25, 0x2e, 0x36, + 0x3d, 0x3e, 0x46, 0x45, 0x4e, 0x55, 0x66, 0x0d, + 0x15, 0x1d, 0x24, 0x2d, 0x2c, 0x35, 0x3c, 0x43, + 0x44, 0x4d, 0x54, 0x5b, 0x5a, 0x14, 0x1c, 0x1b, + 0x23, 0x2b, 0x34, 0x33, 0x3b, 0x42, 0x4b, 0x4c, + 0x52, 0x0e, 0x12, 0x5d, 0x1a, 0x22, 0x21, 0x2a, + 0x32, 0x31, 0x3a, 0x41, 0x49, 0x4a, 0x59, 0x7c, + 0x11, 0x29, 0x58, 0x05, 0x06, 0x04, 0x0c, 0x03, + 0x0b, 0x83, 0x0a, 0x01, 0x09, 0x77, 0x7e, 0x6c, + 0x75, 0x7d, 0x7b, 0x6b, 0x73, 0x74, 0x79, 0x69, + 0x72, 0x7a, 0x70, 0x71, 0x84, 0x60, 0x61, 0x78, + 0x07, 0x0f, 0x17, 0x1f, 0x27, 0x2f, 0x37, 0x3f, + 0x47, 0x4f, 0x56, 0x5e, 0x08, 0x10, 0x18, 0x20, + 0x28, 0x30, 0x38, 0x40, 0x48, 0x50, 0x57, 0x6f, + 0x13, 0x19, 0x39, 0x51, 0x53, 0x5c, 0x5f, 0x62, + 0x63, 0x64, 0x65, 0x67, 0x68, 0x6a, 0x6d, 0x6e, +}; + static void fifo_init(struct ps2kbd_softc *sc) { @@ -315,26 +335,32 @@ ps2kbd_write(struct ps2kbd_softc *sc, uint8_t val) */ static void ps2kbd_keysym_queue(struct ps2kbd_softc *sc, - int down, uint32_t keysym) + int down, uint32_t keysym, uint32_t keycode) { assert(pthread_mutex_isowned_np(&sc->mtx)); int e0_prefix, found; uint8_t code; const struct extended_translation *trans; - found = 0; - if (keysym < 0x80) { - code = ascii_translations[keysym]; - e0_prefix = 0; + if (keycode) { + code = keyset1to2_translations[(uint8_t)(keycode & 0x7f)]; + e0_prefix = ((keycode & 0x80) ? SCANCODE_E0_PREFIX : 0); found = 1; } else { - for (trans = &(extended_translations[0]); trans->keysym != 0; - trans++) { - if (keysym == trans->keysym) { - code = trans->scancode; - e0_prefix = trans->flags & SCANCODE_E0_PREFIX; - found = 1; - break; + found = 0; + if (keysym < 0x80) { + code = ascii_translations[keysym]; + e0_prefix = 0; + found = 1; + } else { + for (trans = &(extended_translations[0]); trans->keysym != 0; + trans++) { + if (keysym == trans->keysym) { + code = trans->scancode; + e0_prefix = trans->flags & SCANCODE_E0_PREFIX; + found = 1; + break; + } } } } @@ -352,7 +378,7 @@ ps2kbd_keysym_queue(struct ps2kbd_softc *sc, } static void -ps2kbd_event(int down, uint32_t keysym, void *arg) +ps2kbd_event(int down, uint32_t keysym, uint32_t keycode, void *arg) { struct ps2kbd_softc *sc = arg; int fifo_full; @@ -363,7 +389,7 @@ ps2kbd_event(int down, uint32_t keysym, void *arg) return; } fifo_full = sc->fifo.num == PS2KBD_FIFOSZ; - ps2kbd_keysym_queue(sc, down, keysym); + ps2kbd_keysym_queue(sc, down, keysym, keycode); pthread_mutex_unlock(&sc->mtx); if (!fifo_full) diff --git a/usr.sbin/bhyve/rfb.c b/usr.sbin/bhyve/rfb.c index 2a7493f8fd6a..d0d33258bfb1 100644 --- a/usr.sbin/bhyve/rfb.c +++ b/usr.sbin/bhyve/rfb.c @@ -98,6 +98,7 @@ static int rfb_debug = 0; #define CS_KEY_EVENT 4 #define CS_POINTER_EVENT 5 #define CS_CUT_TEXT 6 +#define CS_MSG_CLIENT_QEMU 255 #define SECURITY_TYPE_NONE 1 #define SECURITY_TYPE_VNC_AUTH 2 @@ -118,6 +119,9 @@ struct rfb_softc { bool enc_raw_ok; bool enc_zlib_ok; bool enc_resize_ok; + bool enc_extkeyevent_ok; + + bool enc_extkeyevent_send; z_stream zstream; uint8_t *zbuf; @@ -170,6 +174,9 @@ struct rfb_pixfmt_msg { #define RFB_ENCODING_RAW 0 #define RFB_ENCODING_ZLIB 6 #define RFB_ENCODING_RESIZE -223 +#define RFB_ENCODING_EXT_KEYEVENT -258 + +#define RFB_CLIENTMSG_EXT_KEYEVENT 0 #define RFB_MAX_WIDTH 2000 #define RFB_MAX_HEIGHT 1200 @@ -197,6 +204,19 @@ struct rfb_key_msg { uint8_t type; uint8_t down; uint16_t pad; + uint32_t sym; +}; + +struct rfb_client_msg { + uint8_t type; + uint8_t subtype; +}; + +struct rfb_extended_key_msg { + uint8_t type; + uint8_t subtype; + uint16_t down; + uint32_t sym; uint32_t code; }; @@ -276,6 +296,27 @@ rfb_send_resize_update_msg(struct rfb_softc *rc, int cfd) stream_write(cfd, &srect_hdr, sizeof(struct rfb_srvr_rect_hdr)); } +static void +rfb_send_extended_keyevent_update_msg(struct rfb_softc *rc, int cfd) +{ + struct rfb_srvr_updt_msg supdt_msg; + struct rfb_srvr_rect_hdr srect_hdr; + + /* Number of rectangles: 1 */ + supdt_msg.type = 0; + supdt_msg.pad = 0; + supdt_msg.numrects = htons(1); + stream_write(cfd, &supdt_msg, sizeof(struct rfb_srvr_updt_msg)); + + /* Rectangle header */ + srect_hdr.x = htons(0); + srect_hdr.y = htons(0); + srect_hdr.width = htons(rc->width); + srect_hdr.height = htons(rc->height); + srect_hdr.encoding = htonl(RFB_ENCODING_EXT_KEYEVENT); + stream_write(cfd, &srect_hdr, sizeof(struct rfb_srvr_rect_hdr)); +} + static void rfb_recv_set_pixfmt_msg(struct rfb_softc *rc, int cfd) { @@ -309,6 +350,9 @@ rfb_recv_set_encodings_msg(struct rfb_softc *rc, int cfd) case RFB_ENCODING_RESIZE: rc->enc_resize_ok = true; break; + case RFB_ENCODING_EXT_KEYEVENT: + rc->enc_extkeyevent_ok = true; + break; } } } @@ -686,6 +730,11 @@ rfb_recv_update_msg(struct rfb_softc *rc, int cfd) (void)stream_read(cfd, ((void *)&updt_msg) + 1 , sizeof(updt_msg) - 1); + if (rc->enc_extkeyevent_ok && (!rc->enc_extkeyevent_send)) { + rfb_send_extended_keyevent_update_msg(rc, cfd); + rc->enc_extkeyevent_send = true; + } + rc->pending = true; if (!updt_msg.incremental) rc->update_all = true; @@ -698,10 +747,25 @@ rfb_recv_key_msg(struct rfb_softc *rc, int cfd) (void)stream_read(cfd, ((void *)&key_msg) + 1, sizeof(key_msg) - 1); - console_key_event(key_msg.down, htonl(key_msg.code)); + console_key_event(key_msg.down, htonl(key_msg.sym), htonl(0)); rc->input_detected = true; } +static void +rfb_recv_client_msg(struct rfb_softc *rc, int cfd) +{ + struct rfb_client_msg client_msg; + struct rfb_extended_key_msg extkey_msg; + + (void)stream_read(cfd, ((void *)&client_msg) + 1, sizeof(client_msg) - 1); + + if (client_msg.subtype == RFB_CLIENTMSG_EXT_KEYEVENT ) { + (void)stream_read(cfd, ((void *)&extkey_msg) + 2, sizeof(extkey_msg) - 2); + console_key_event((int)extkey_msg.down, htonl(extkey_msg.sym), htonl(extkey_msg.code)); + rc->input_detected = true; + } +} + static void rfb_recv_ptr_msg(struct rfb_softc *rc, int cfd) { @@ -1000,6 +1064,9 @@ report_and_done: case CS_CUT_TEXT: rfb_recv_cuttext_msg(rc, cfd); break; + case CS_MSG_CLIENT_QEMU: + rfb_recv_client_msg(rc, cfd); + break; default: WPRINTF(("rfb unknown cli-code %d!", buf[0] & 0xff)); goto done; @@ -1034,6 +1101,9 @@ rfb_thr(void *arg) rc->enc_raw_ok = false; rc->enc_zlib_ok = false; rc->enc_resize_ok = false; + rc->enc_extkeyevent_ok = false; + + rc->enc_extkeyevent_send = false; cfd = accept(rc->sfd, NULL, NULL); if (rc->conn_wait) {