NetBSD Problem Report #48360

From www@NetBSD.org  Sat Nov  2 09:44:38 2013
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 5B677A610B
	for <gnats-bugs@gnats.NetBSD.org>; Sat,  2 Nov 2013 09:44:38 +0000 (UTC)
Message-Id: <20131102094436.BDD0BA6114@mollari.NetBSD.org>
Date: Sat,  2 Nov 2013 09:44:36 +0000 (UTC)
From: nathanialsloss@yahoo.com.au
Reply-To: nathanialsloss@yahoo.com.au
To: gnats-bugs@NetBSD.org
Subject: wskbd - support for cn_magic
X-Send-Pr-Version: www-1.0

>Number:         48360
>Category:       kern
>Synopsis:       wskbd - support for cn_magic
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Nov 02 09:45:00 +0000 2013
>Last-Modified:  Mon Mar 10 11:15:00 +0000 2014
>Originator:     Nat Sloss
>Release:        NetBSD 6.1.1
>Organization:
>Environment:
NetBSD beast 6.1.1_PATCH NetBSD 6.1.1_PATCH (PCIPAE) #13: Sat Nov  2 18:07:05 EST 2013  build@test:/usr/src/sys/arch/i386/compile/obj/PCIPAE i386
>Description:
wscons does not support cn_magic - setting hw.cnmagic has no effect.

So I have a simple patch that adds support, although it probably needs some reworking.

Also I did not know the byte sequence for C-A-Esc so I used KS_Cmd_Debugger.  As a consequence the debugger can also be entered with " (curcumflex modifier)" KS_circumflex, which I did not know how to enter from my keyboard in /bin/ksh.

But Apart from that it works well.

I also found that even without this patch the debugger can be entered from any virtual terminal except  vt5 (used for x windows) this was not the case in NetBSD 5.0.1.


>How-To-Repeat:
Refer to above.
>Fix:
Apply this patch:
Index: src/sys/dev/wscons/wskbd.c
===================================================================
RCS file: /cvsroot/src/sys/dev/wscons/wskbd.c,v
retrieving revision 1.130
diff -u -r1.130 wskbd.c
--- src/sys/dev/wscons/wskbd.c	26 Oct 2010 05:12:34 -0000	1.130
+++ src/sys/dev/wscons/wskbd.c	2 Nov 2013 09:23:10 -0000
@@ -207,6 +207,7 @@

 	wskbd_hotkey_plugin *sc_hotkey;
 	void *sc_hotkeycookie;
+	dev_t		cn_magicdev;	/* device for cnmagic */
 };

 #define MOD_SHIFT_L		(1 << 0)
@@ -241,6 +242,19 @@
 		dst |= (src & MOD_META_L) ? MOD_META_L : 0; \
 		dst |= (src & MOD_META_R) ? MOD_META_R : 0; \
 	} while (0)
+#define ws_check_magic(k, s)						\
+	do {								\
+			int _v = (s).cnm_magic[(s).cnm_state];		\
+			if ((k) == CNS_MAGIC_VAL(_v)) {			\
+				(s).cnm_state = CNS_MAGIC_NEXT(_v);	\
+				if ((s).cnm_state == CNS_TERM) {	\
+					cn_trap();			\
+					(s).cnm_state = 0;		\
+				}					\
+			} else {					\
+				(s).cnm_state = 0;			\
+			}						\
+	} while (/* CONSTCOND */ 0)

 static int  wskbd_match(device_t, cfdata_t, void *);
 static void wskbd_attach(device_t, device_t, void *);
@@ -350,6 +364,9 @@
 static bool wskbd_suspend(device_t dv, const pmf_qual_t *);
 static void wskbd_repeat(void *v);

+#include <dev/cons.h>
+static struct cnm_state ws_cnm_state;
+
 static int wskbd_console_initted;
 static struct wskbd_softc *wskbd_console_device;
 static struct wskbd_internal wskbd_console_data;
@@ -438,6 +455,11 @@

 	if (ap->console) {
 		sc->id = &wskbd_console_data;
+
+		sc->cn_magicdev = cn_tab->cn_dev;
+		cn_init_magic(&ws_cnm_state);
+		cn_set_magic("\x20\xf4"); /* default magic */
+
 	} else {
 		sc->id = malloc(sizeof(struct wskbd_internal),
 				M_DEVBUF, M_WAITOK|M_ZERO);
@@ -526,7 +548,7 @@

 	wskbd_console_data.t_consops = consops;
 	wskbd_console_data.t_consaccesscookie = conscookie;
-
+	
 #if NWSDISPLAY > 0
 	wsdisplay_set_cons_kbd(wskbd_cngetc, wskbd_cnpollc, wskbd_cnbell);
 #endif
@@ -1583,7 +1605,9 @@
 		return (0);

 #if defined(DDB) || defined(KGDB)
+
 	if (ksym == KS_Cmd_Debugger) {
+#if 0
 		if (sc->sc_isconsole) {
 #ifdef DDB
 			console_debugger();
@@ -1592,6 +1616,7 @@
 			kgdb_connect(1);
 #endif
 		}
+#endif
 		/* discard this key (ddb discarded command modifiers) */
 		*type = WSCONS_EVENT_KEY_UP;
 		return (1);
@@ -1713,9 +1738,17 @@
 	}

 	/* if this key has a command, process it first */
-	if (sc != NULL && kp->command != KS_voidSymbol)
+	if (sc != NULL && kp->command != KS_voidSymbol) {
 		iscommand = internal_command(sc, &type, kp->command,
 					     kp->group1[0]);
+		if (sc->sc_isconsole && iscommand) {
+			if (kp->command & 0xff)
+				ws_check_magic((kp->command & 0xff), ws_cnm_state);
+			if ((kp->command >> 8) & 0xff)
+				ws_check_magic(((kp->command >> 8) & 0xff), ws_cnm_state);
+		}
+
+	}

 	/* Now update modifiers */
 	switch (kp->group1[0]) {
@@ -1868,12 +1901,32 @@
 			if (id->t_flags & WSKFL_METAESC) {
 				id->t_symbols[0] = KS_Escape;
 				id->t_symbols[1] = res;
+				if (sc != NULL && sc->sc_isconsole) {
+					if (res & 0xff)
+						ws_check_magic((res & 0xff), ws_cnm_state);
+					if ((res >> 8) & 0xff)
+						ws_check_magic(((res >> 8) & 0xff), ws_cnm_state);
+					if (KS_Escape & 0xff)
+						ws_check_magic((KS_Escape & 0xff), ws_cnm_state);
+					if ((KS_Escape >> 8) & 0xff)
+						ws_check_magic(((KS_Escape >> 8) & 0xff), ws_cnm_state);
+				}
+
 				return (2);
 			} else
 				res |= 0x80;
 		}
+	
 	}

 	id->t_symbols[0] = res;
+
+	if (sc != NULL && sc->sc_isconsole) {
+		if (res & 0xff)
+			ws_check_magic((res & 0xff), ws_cnm_state);
+		if ((res >> 8) & 0xff)
+			ws_check_magic(((res >> 8) & 0xff), ws_cnm_state);
+	}
+
 	return (1);
 }

It works - but it definately needs reworking.

NB: This patch is my own work, which I submit under the NetBSD license.

I hope others find this useful.

Regards,

Nat.

>Audit-Trail:
From: Nat Sloss <nathanialsloss@yahoo.com.au>
To: "gnats-bugs" <gnats-bugs@netbsd.org>
Cc: 
Subject: Re: kern/48360 wskbd - support for cn_magic
Date: Mon, 10 Mar 2014 22:13:01 +1100

 Here is a better patch:
 Index: src/sys/dev/wscons/wskbd.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/wscons/wskbd.c,v
 retrieving revision 1.130
 diff -u -r1.130 wskbd.c
 --- src/sys/dev/wscons/wskbd.c	26 Oct 2010 05:12:34 -0000	1.130
 +++ src/sys/dev/wscons/wskbd.c	10 Mar 2014 11:04:02 -0000
 @@ -207,6 +207,7 @@

  	wskbd_hotkey_plugin *sc_hotkey;
  	void *sc_hotkeycookie;
 +	dev_t		cn_magicdev;	/* device for cnmagic */
  };

  #define MOD_SHIFT_L		(1 << 0)
 @@ -241,6 +242,26 @@
  		dst |= (src & MOD_META_L) ? MOD_META_L : 0; \
  		dst |= (src & MOD_META_R) ? MOD_META_R : 0; \
  	} while (0)
 +#define ws_check_magic(c, k, s)							\
 +	do {									\
 +			int _v = (s).cnm_magic[(s).cnm_state];			\
 +			int _u = (s).cnm_magic[0];				\
 +			if ((c) == CNS_MAGIC_VAL(_u)) {				\
 +				if ((s).cnm_state == 0) {			\
 +					(s).cnm_state = CNS_MAGIC_NEXT(_v);	\
 +					_v = (s).cnm_magic[(s).cnm_state];	\
 +				}						\
 +				if ((k) == CNS_MAGIC_VAL(_v)) {			\
 +					(s).cnm_state = CNS_MAGIC_NEXT(_v);	\
 +					if ((s).cnm_state == CNS_TERM) {	\
 +						cn_trap();			\
 +						(s).cnm_state = 0;		\
 +					}					\
 +				} else {					\
 +					(s).cnm_state = 0;			\
 +				}						\
 +			}							\
 +	} while (/* CONSTCOND */ 0)

  static int  wskbd_match(device_t, cfdata_t, void *);
  static void wskbd_attach(device_t, device_t, void *);
 @@ -350,6 +371,9 @@
  static bool wskbd_suspend(device_t dv, const pmf_qual_t *);
  static void wskbd_repeat(void *v);

 +#include <dev/cons.h>
 +static struct cnm_state ws_cnm_state;
 +
  static int wskbd_console_initted;
  static struct wskbd_softc *wskbd_console_device;
  static struct wskbd_internal wskbd_console_data;
 @@ -438,6 +462,11 @@

  	if (ap->console) {
  		sc->id = &wskbd_console_data;
 +
 +		sc->cn_magicdev = cn_tab->cn_dev;
 +		cn_init_magic(&ws_cnm_state);
 +		cn_set_magic("\x2\x20\xf4"); /* default magic */
 +
  	} else {
  		sc->id = malloc(sizeof(struct wskbd_internal),
  				M_DEVBUF, M_WAITOK|M_ZERO);
 @@ -526,7 +555,7 @@

  	wskbd_console_data.t_consops = consops;
  	wskbd_console_data.t_consaccesscookie = conscookie;
 -
 +	
  #if NWSDISPLAY > 0
  	wsdisplay_set_cons_kbd(wskbd_cngetc, wskbd_cnpollc, wskbd_cnbell);
  #endif
 @@ -1583,7 +1612,9 @@
  		return (0);

  #if defined(DDB) || defined(KGDB)
 +
  	if (ksym == KS_Cmd_Debugger) {
 +#if 0
  		if (sc->sc_isconsole) {
  #ifdef DDB
  			console_debugger();
 @@ -1592,6 +1623,7 @@
  			kgdb_connect(1);
  #endif
  		}
 +#endif
  		/* discard this key (ddb discarded command modifiers) */
  		*type = WSCONS_EVENT_KEY_UP;
  		return (1);
 @@ -1713,9 +1745,18 @@
  	}

  	/* if this key has a command, process it first */
 -	if (sc != NULL && kp->command != KS_voidSymbol)
 +	if (sc != NULL && kp->command != KS_voidSymbol) {
  		iscommand = internal_command(sc, &type, kp->command,
  					     kp->group1[0]);
 +		if (sc->sc_isconsole && iscommand) {
 +			if (kp->command & 0xff)
 +				ws_check_magic(2, (kp->command & 0xff), ws_cnm_state);
 +			if ((kp->command >> 8) & 0xff)
 +				ws_check_magic(2, ((kp->command >> 8) & 0xff),
 +				     ws_cnm_state);
 +		}
 +
 +	}

  	/* Now update modifiers */
  	switch (kp->group1[0]) {
 @@ -1868,12 +1909,32 @@
  			if (id->t_flags & WSKFL_METAESC) {
  				id->t_symbols[0] = KS_Escape;
  				id->t_symbols[1] = res;
 +				if (sc != NULL && sc->sc_isconsole) {
 +					if (res & 0xff)
 +						ws_check_magic(1, (res & 0xff), ws_cnm_state);
 +					if ((res >> 8) & 0xff)
 +						ws_check_magic(1, ((res >> 8) & 0xff), 
 ws_cnm_state);
 +					if (KS_Escape & 0xff)
 +						ws_check_magic(1, (KS_Escape & 0xff), 
 ws_cnm_state);
 +					if ((KS_Escape >> 8) & 0xff)
 +						ws_check_magic(1, ((KS_Escape >> 8) & 0xff), 
 ws_cnm_state);
 +				}
 +
  				return (2);
  			} else
  				res |= 0x80;
  		}
 +	
  	}

  	id->t_symbols[0] = res;
 +
 +	if (sc != NULL && sc->sc_isconsole) {
 +		if (res & 0xff)
 +			ws_check_magic(1, (res & 0xff), ws_cnm_state);
 +		if ((res >> 8) & 0xff)
 +			ws_check_magic(1, ((res >> 8) & 0xff), ws_cnm_state);
 +	}
 +
  	return (1);
  }

 The magic should be prefixed by \x1 for regular keystrokes or \x2 for wskbd 
 commands, you cannot mix both types in magic.

 Regards,

 Nat. 

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.