10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51272Slq150181 * Common Development and Distribution License (the "License"). 61272Slq150181 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 211272Slq150181 220Sstevel@tonic-gate /* 233505Sqz150045 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate /* 300Sstevel@tonic-gate * Generic keyboard support: streams and administration. 310Sstevel@tonic-gate */ 320Sstevel@tonic-gate 330Sstevel@tonic-gate #define KEYMAP_SIZE_VARIABLE 340Sstevel@tonic-gate 350Sstevel@tonic-gate #include <sys/types.h> 360Sstevel@tonic-gate #include <sys/cred.h> 370Sstevel@tonic-gate #include <sys/stream.h> 380Sstevel@tonic-gate #include <sys/stropts.h> 390Sstevel@tonic-gate #include <sys/strsun.h> 400Sstevel@tonic-gate #include <sys/ddi.h> 410Sstevel@tonic-gate #include <sys/vuid_event.h> 420Sstevel@tonic-gate #include <sys/modctl.h> 430Sstevel@tonic-gate #include <sys/errno.h> 440Sstevel@tonic-gate #include <sys/kmem.h> 450Sstevel@tonic-gate #include <sys/cmn_err.h> 460Sstevel@tonic-gate #include <sys/kbd.h> 470Sstevel@tonic-gate #include <sys/kbio.h> 480Sstevel@tonic-gate #include <sys/consdev.h> 490Sstevel@tonic-gate #include <sys/kbtrans.h> 500Sstevel@tonic-gate #include <sys/policy.h> 510Sstevel@tonic-gate #include "kbtrans_lower.h" 520Sstevel@tonic-gate #include "kbtrans_streams.h" 530Sstevel@tonic-gate 540Sstevel@tonic-gate #ifdef DEBUG 550Sstevel@tonic-gate int kbtrans_errmask; 560Sstevel@tonic-gate int kbtrans_errlevel; 570Sstevel@tonic-gate #endif 580Sstevel@tonic-gate 590Sstevel@tonic-gate /* 600Sstevel@tonic-gate * Repeat rates set in static variables so they can be tweeked with 610Sstevel@tonic-gate * debugger. 620Sstevel@tonic-gate */ 630Sstevel@tonic-gate static int kbtrans_repeat_rate; 640Sstevel@tonic-gate static int kbtrans_repeat_delay; 650Sstevel@tonic-gate 660Sstevel@tonic-gate /* Printing message on q overflow */ 670Sstevel@tonic-gate static int kbtrans_overflow_msg = 1; 680Sstevel@tonic-gate 690Sstevel@tonic-gate /* 700Sstevel@tonic-gate * This value corresponds approximately to max 10 fingers 710Sstevel@tonic-gate */ 720Sstevel@tonic-gate static int kbtrans_downs_size = 15; 730Sstevel@tonic-gate 740Sstevel@tonic-gate /* 750Sstevel@tonic-gate * modload support 760Sstevel@tonic-gate */ 770Sstevel@tonic-gate extern struct mod_ops mod_miscops; 780Sstevel@tonic-gate 790Sstevel@tonic-gate static struct modlmisc modlmisc = { 800Sstevel@tonic-gate &mod_miscops, /* Type of module */ 810Sstevel@tonic-gate "kbtrans (key translation) 1.32" 820Sstevel@tonic-gate }; 830Sstevel@tonic-gate 840Sstevel@tonic-gate static struct modlinkage modlinkage = { 850Sstevel@tonic-gate MODREV_1, (void *)&modlmisc, NULL 860Sstevel@tonic-gate }; 870Sstevel@tonic-gate 880Sstevel@tonic-gate int 890Sstevel@tonic-gate _init(void) 900Sstevel@tonic-gate { 910Sstevel@tonic-gate return (mod_install(&modlinkage)); 920Sstevel@tonic-gate } 930Sstevel@tonic-gate 940Sstevel@tonic-gate int 950Sstevel@tonic-gate _fini(void) 960Sstevel@tonic-gate { 970Sstevel@tonic-gate return (mod_remove(&modlinkage)); 980Sstevel@tonic-gate } 990Sstevel@tonic-gate 1000Sstevel@tonic-gate int 1010Sstevel@tonic-gate _info(struct modinfo *modinfop) 1020Sstevel@tonic-gate { 1030Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 1040Sstevel@tonic-gate } 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate /* 1070Sstevel@tonic-gate * Internal Function Prototypes 1080Sstevel@tonic-gate */ 1090Sstevel@tonic-gate static char *kbtrans_strsetwithdecimal(char *, uint_t, uint_t); 1100Sstevel@tonic-gate static void kbtrans_set_translation_callback(struct kbtrans *); 1110Sstevel@tonic-gate static void kbtrans_reioctl(void *); 1120Sstevel@tonic-gate static void kbtrans_send_esc_event(char, struct kbtrans *); 1130Sstevel@tonic-gate static void kbtrans_keypressed(struct kbtrans *, uchar_t, Firm_event *, 1140Sstevel@tonic-gate ushort_t); 1150Sstevel@tonic-gate static void kbtrans_putbuf(char *, queue_t *); 1160Sstevel@tonic-gate static void kbtrans_cancelrpt(struct kbtrans *); 1170Sstevel@tonic-gate static void kbtrans_queuepress(struct kbtrans *, uchar_t, Firm_event *); 1180Sstevel@tonic-gate static void kbtrans_putcode(register struct kbtrans *, uint_t); 1190Sstevel@tonic-gate static void kbtrans_keyreleased(struct kbtrans *, uchar_t); 1200Sstevel@tonic-gate static void kbtrans_queueevent(struct kbtrans *, Firm_event *); 1210Sstevel@tonic-gate static void kbtrans_untrans_keypressed_raw(struct kbtrans *, kbtrans_key_t); 1220Sstevel@tonic-gate static void kbtrans_untrans_keyreleased_raw(struct kbtrans *, 1230Sstevel@tonic-gate kbtrans_key_t); 1240Sstevel@tonic-gate static void kbtrans_ascii_keypressed(struct kbtrans *, uint_t, 1250Sstevel@tonic-gate kbtrans_key_t, uint_t); 1260Sstevel@tonic-gate static void kbtrans_ascii_keyreleased(struct kbtrans *, kbtrans_key_t); 1270Sstevel@tonic-gate static void kbtrans_ascii_setup_repeat(struct kbtrans *, uint_t, 1280Sstevel@tonic-gate kbtrans_key_t); 1290Sstevel@tonic-gate static void kbtrans_trans_event_keypressed(struct kbtrans *, uint_t, 1300Sstevel@tonic-gate kbtrans_key_t, uint_t); 1310Sstevel@tonic-gate static void kbtrans_trans_event_keyreleased(struct kbtrans *, 1320Sstevel@tonic-gate kbtrans_key_t); 1330Sstevel@tonic-gate static void kbtrans_trans_event_setup_repeat(struct kbtrans *, uint_t, 1340Sstevel@tonic-gate kbtrans_key_t); 1350Sstevel@tonic-gate static void kbtrans_rpt(void *); 1360Sstevel@tonic-gate static void kbtrans_setled(struct kbtrans *); 1370Sstevel@tonic-gate static void kbtrans_flush(struct kbtrans *); 1380Sstevel@tonic-gate static enum kbtrans_message_response kbtrans_ioctl(struct kbtrans *upper, 1390Sstevel@tonic-gate mblk_t *mp); 1400Sstevel@tonic-gate static int kbtrans_setkey(struct kbtrans_lower *, struct kiockey *, 1410Sstevel@tonic-gate cred_t *); 1420Sstevel@tonic-gate static int kbtrans_getkey(struct kbtrans_lower *, struct kiockey *); 1430Sstevel@tonic-gate static int kbtrans_skey(struct kbtrans_lower *, struct kiockeymap *, 1440Sstevel@tonic-gate cred_t *cr); 1450Sstevel@tonic-gate static int kbtrans_gkey(struct kbtrans_lower *, struct kiockeymap *); 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate /* 1480Sstevel@tonic-gate * Keyboard Translation Mode (TR_NONE) 1490Sstevel@tonic-gate * 1500Sstevel@tonic-gate * Functions to be called when keyboard translation is turned off 1510Sstevel@tonic-gate * and up/down key codes are reported. 1520Sstevel@tonic-gate */ 1530Sstevel@tonic-gate struct keyboard_callback untrans_event_callback = { 1540Sstevel@tonic-gate kbtrans_untrans_keypressed_raw, 1550Sstevel@tonic-gate kbtrans_untrans_keyreleased_raw, 1560Sstevel@tonic-gate NULL, 1570Sstevel@tonic-gate NULL, 1580Sstevel@tonic-gate NULL, 1590Sstevel@tonic-gate NULL, 1600Sstevel@tonic-gate NULL, 1610Sstevel@tonic-gate }; 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate /* 1640Sstevel@tonic-gate * Keyboard Translation Mode (TR_ASCII) 1650Sstevel@tonic-gate * 1660Sstevel@tonic-gate * Functions to be called when ISO 8859/1 codes are reported 1670Sstevel@tonic-gate */ 1680Sstevel@tonic-gate struct keyboard_callback ascii_callback = { 1690Sstevel@tonic-gate NULL, 1700Sstevel@tonic-gate NULL, 1710Sstevel@tonic-gate kbtrans_ascii_keypressed, 1720Sstevel@tonic-gate kbtrans_ascii_keyreleased, 1730Sstevel@tonic-gate kbtrans_ascii_setup_repeat, 1740Sstevel@tonic-gate kbtrans_cancelrpt, 1750Sstevel@tonic-gate kbtrans_setled, 1760Sstevel@tonic-gate }; 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate /* 1790Sstevel@tonic-gate * Keyboard Translation Mode (TR_EVENT) 1800Sstevel@tonic-gate * 1810Sstevel@tonic-gate * Functions to be called when firm_events are reported. 1820Sstevel@tonic-gate */ 1830Sstevel@tonic-gate struct keyboard_callback trans_event_callback = { 1840Sstevel@tonic-gate NULL, 1850Sstevel@tonic-gate NULL, 1860Sstevel@tonic-gate kbtrans_trans_event_keypressed, 1870Sstevel@tonic-gate kbtrans_trans_event_keyreleased, 1880Sstevel@tonic-gate kbtrans_trans_event_setup_repeat, 1890Sstevel@tonic-gate kbtrans_cancelrpt, 1900Sstevel@tonic-gate kbtrans_setled, 1910Sstevel@tonic-gate }; 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate /* 1940Sstevel@tonic-gate * kbtrans_streams_init: 1950Sstevel@tonic-gate * Initialize the stream, keytables, callbacks, etc. 1960Sstevel@tonic-gate */ 1970Sstevel@tonic-gate int 1980Sstevel@tonic-gate kbtrans_streams_init( 1990Sstevel@tonic-gate queue_t *q, 2000Sstevel@tonic-gate int sflag, 2010Sstevel@tonic-gate cred_t *crp, 2020Sstevel@tonic-gate struct kbtrans_hardware *hw, 2030Sstevel@tonic-gate struct kbtrans_callbacks *hw_cb, 2040Sstevel@tonic-gate struct kbtrans **ret_kbd, 2050Sstevel@tonic-gate int initial_leds, 2060Sstevel@tonic-gate int initial_led_mask) 2070Sstevel@tonic-gate { 2080Sstevel@tonic-gate struct kbtrans *upper; 2090Sstevel@tonic-gate struct kbtrans_lower *lower; 2100Sstevel@tonic-gate int err; 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate /* 2130Sstevel@tonic-gate * Default to relatively generic tables. 2140Sstevel@tonic-gate */ 2150Sstevel@tonic-gate extern signed char kb_compose_map[]; 2160Sstevel@tonic-gate extern struct compose_sequence_t kb_compose_table[]; 2170Sstevel@tonic-gate extern struct fltaccent_sequence_t kb_fltaccent_table[]; 2180Sstevel@tonic-gate extern char keystringtab[][KTAB_STRLEN]; 2190Sstevel@tonic-gate extern unsigned char kb_numlock_table[]; 2200Sstevel@tonic-gate 2210Sstevel@tonic-gate /* Set these up only once so that they could be changed from adb */ 2220Sstevel@tonic-gate if (!kbtrans_repeat_rate) { 2230Sstevel@tonic-gate kbtrans_repeat_rate = (hz+29)/30; 2240Sstevel@tonic-gate kbtrans_repeat_delay = hz/2; 2250Sstevel@tonic-gate } 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate /* 2280Sstevel@tonic-gate * Only allow open requests to succeed for privileged users. This 2290Sstevel@tonic-gate * necessary to prevent users from pushing the this module again 2300Sstevel@tonic-gate * on the stream associated with /dev/kbd. 2310Sstevel@tonic-gate */ 2320Sstevel@tonic-gate err = secpolicy_console(crp); 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate if (err != 0) { 2350Sstevel@tonic-gate return (err); 2360Sstevel@tonic-gate } 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate switch (sflag) { 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate case MODOPEN: 2410Sstevel@tonic-gate break; 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate case CLONEOPEN: 2440Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_OPEN, (NULL, 2450Sstevel@tonic-gate "kbtrans_streams_init: Clone open not supported")); 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate return (EINVAL); 2480Sstevel@tonic-gate } 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate /* allocate keyboard state structure */ 2510Sstevel@tonic-gate upper = kmem_zalloc(sizeof (struct kbtrans), KM_SLEEP); 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate *ret_kbd = upper; 2540Sstevel@tonic-gate 2550Sstevel@tonic-gate upper->kbtrans_polled_buf[0] = '\0'; 2560Sstevel@tonic-gate upper->kbtrans_polled_pending_chars = upper->kbtrans_polled_buf; 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate upper->kbtrans_streams_hw = hw; 2590Sstevel@tonic-gate upper->kbtrans_streams_hw_callbacks = hw_cb; 2600Sstevel@tonic-gate upper->kbtrans_streams_readq = q; 2610Sstevel@tonic-gate upper->kbtrans_streams_iocpending = NULL; 2620Sstevel@tonic-gate upper->kbtrans_streams_translatable = TR_CAN; 2630Sstevel@tonic-gate upper->kbtrans_overflow_cnt = 0; 2640Sstevel@tonic-gate upper->kbtrans_streams_translate_mode = TR_ASCII; 2650Sstevel@tonic-gate 2660Sstevel@tonic-gate /* Set the translation callback based on the translation type */ 2670Sstevel@tonic-gate kbtrans_set_translation_callback(upper); 2680Sstevel@tonic-gate 2690Sstevel@tonic-gate lower = &upper->kbtrans_lower; 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate /* 2720Sstevel@tonic-gate * Set defaults for relatively generic tables. 2730Sstevel@tonic-gate */ 2740Sstevel@tonic-gate lower->kbtrans_compose_map = kb_compose_map; 2750Sstevel@tonic-gate lower->kbtrans_compose_table = kb_compose_table; 2760Sstevel@tonic-gate lower->kbtrans_fltaccent_table = kb_fltaccent_table; 2770Sstevel@tonic-gate lower->kbtrans_numlock_table = kb_numlock_table; 2780Sstevel@tonic-gate lower->kbtrans_keystringtab = keystringtab; 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate lower->kbtrans_upper = upper; 2810Sstevel@tonic-gate lower->kbtrans_compat = 1; 2820Sstevel@tonic-gate 2830Sstevel@tonic-gate /* 2840Sstevel@tonic-gate * We have a generic default for the LED state, and let the 2850Sstevel@tonic-gate * hardware-specific driver supply overrides. 2860Sstevel@tonic-gate */ 2870Sstevel@tonic-gate lower->kbtrans_led_state = 0; 2880Sstevel@tonic-gate lower->kbtrans_led_state &= ~initial_led_mask; 2890Sstevel@tonic-gate lower->kbtrans_led_state |= initial_leds; 2900Sstevel@tonic-gate lower->kbtrans_togglemask = 0; 2910Sstevel@tonic-gate 2920Sstevel@tonic-gate if (lower->kbtrans_led_state & LED_CAPS_LOCK) 2930Sstevel@tonic-gate lower->kbtrans_togglemask |= CAPSMASK; 2940Sstevel@tonic-gate if (lower->kbtrans_led_state & LED_NUM_LOCK) 2950Sstevel@tonic-gate lower->kbtrans_togglemask |= NUMLOCKMASK; 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate #if defined(SCROLLMASK) 2980Sstevel@tonic-gate if (lower->kbtrans_led_state & LED_SCROLL_LOCK) 2990Sstevel@tonic-gate lower->kbtrans_togglemask |= SCROLLMASK; 3000Sstevel@tonic-gate #endif 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate lower->kbtrans_shiftmask = lower->kbtrans_togglemask; 3030Sstevel@tonic-gate 3040Sstevel@tonic-gate upper->kbtrans_streams_vuid_addr.ascii = ASCII_FIRST; 3050Sstevel@tonic-gate upper->kbtrans_streams_vuid_addr.top = TOP_FIRST; 3060Sstevel@tonic-gate upper->kbtrans_streams_vuid_addr.vkey = VKEY_FIRST; 3070Sstevel@tonic-gate 3080Sstevel@tonic-gate /* Allocate dynamic memory for downs table */ 3090Sstevel@tonic-gate upper->kbtrans_streams_num_downs_entries = kbtrans_downs_size; 3100Sstevel@tonic-gate upper->kbtrans_streams_downs_bytes = 3110Sstevel@tonic-gate (uint32_t)(kbtrans_downs_size * sizeof (Key_event)); 3120Sstevel@tonic-gate upper->kbtrans_streams_downs = 3130Sstevel@tonic-gate kmem_zalloc(upper->kbtrans_streams_downs_bytes, KM_SLEEP); 3140Sstevel@tonic-gate upper->kbtrans_streams_abortable = B_FALSE; 3150Sstevel@tonic-gate 3160Sstevel@tonic-gate upper->kbtrans_streams_flags = KBTRANS_STREAMS_OPEN; 3170Sstevel@tonic-gate 3180Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_OPEN, (upper, "kbtrans_streams_init " 3190Sstevel@tonic-gate "exiting")); 3200Sstevel@tonic-gate return (0); 3210Sstevel@tonic-gate } 3220Sstevel@tonic-gate 3230Sstevel@tonic-gate 3240Sstevel@tonic-gate /* 3250Sstevel@tonic-gate * kbtrans_streams_fini: 3260Sstevel@tonic-gate * Free structures and uninitialize the stream 3270Sstevel@tonic-gate */ 3280Sstevel@tonic-gate int 3290Sstevel@tonic-gate kbtrans_streams_fini(struct kbtrans *upper) 3300Sstevel@tonic-gate { 3310Sstevel@tonic-gate /* 3320Sstevel@tonic-gate * Since we're about to destroy our private data, turn off 3330Sstevel@tonic-gate * our open flag first, so we don't accept any more input 3340Sstevel@tonic-gate * and try to use that data. 3350Sstevel@tonic-gate */ 3360Sstevel@tonic-gate upper->kbtrans_streams_flags = 0; 3370Sstevel@tonic-gate 3380Sstevel@tonic-gate /* clear all timeouts */ 3390Sstevel@tonic-gate if (upper->kbtrans_streams_bufcallid) { 3400Sstevel@tonic-gate qunbufcall(upper->kbtrans_streams_readq, 3410Sstevel@tonic-gate upper->kbtrans_streams_bufcallid); 3420Sstevel@tonic-gate } 3430Sstevel@tonic-gate if (upper->kbtrans_streams_rptid) { 3440Sstevel@tonic-gate (void) quntimeout(upper->kbtrans_streams_readq, 3450Sstevel@tonic-gate upper->kbtrans_streams_rptid); 3460Sstevel@tonic-gate } 3470Sstevel@tonic-gate kmem_free(upper->kbtrans_streams_downs, 3480Sstevel@tonic-gate upper->kbtrans_streams_downs_bytes); 3490Sstevel@tonic-gate kmem_free(upper, sizeof (struct kbtrans)); 3500Sstevel@tonic-gate 3510Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_CLOSE, (upper, "kbtrans_streams_fini " 3520Sstevel@tonic-gate "exiting")); 3530Sstevel@tonic-gate return (0); 3540Sstevel@tonic-gate } 3550Sstevel@tonic-gate 3560Sstevel@tonic-gate /* 3570Sstevel@tonic-gate * kbtrans_streams_releaseall : 3580Sstevel@tonic-gate * This function releases all the held keys. 3590Sstevel@tonic-gate */ 3600Sstevel@tonic-gate void 3610Sstevel@tonic-gate kbtrans_streams_releaseall(struct kbtrans *upper) 3620Sstevel@tonic-gate { 3630Sstevel@tonic-gate register struct key_event *ke; 3640Sstevel@tonic-gate register int i; 3650Sstevel@tonic-gate 3660Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (NULL, "USBKBM RELEASE ALL\n")); 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate /* Scan table of down key stations */ 3690Sstevel@tonic-gate for (i = 0, ke = upper->kbtrans_streams_downs; 3700Sstevel@tonic-gate i < upper->kbtrans_streams_num_downs_entries; i++, ke++) { 3710Sstevel@tonic-gate 3720Sstevel@tonic-gate /* Key station not zero */ 3730Sstevel@tonic-gate if (ke->key_station) { 3740Sstevel@tonic-gate 3750Sstevel@tonic-gate kbtrans_keyreleased(upper, ke->key_station); 3760Sstevel@tonic-gate /* kbtrans_keyreleased resets downs entry */ 3770Sstevel@tonic-gate } 3780Sstevel@tonic-gate } 3790Sstevel@tonic-gate } 3800Sstevel@tonic-gate 3810Sstevel@tonic-gate /* 3820Sstevel@tonic-gate * kbtrans_streams_message: 3830Sstevel@tonic-gate * keyboard module output queue put procedure: handles M_IOCTL 3840Sstevel@tonic-gate * messages. 3850Sstevel@tonic-gate * 3860Sstevel@tonic-gate * Return KBTRANS_MESSAGE_HANDLED if the message was handled by 3870Sstevel@tonic-gate * kbtrans and KBTRANS_MESSAGE_NOT_HANDLED otherwise. If 3880Sstevel@tonic-gate * KBTRANS_MESSAGE_HANDLED is returned, no further action is required. 3890Sstevel@tonic-gate * If KBTRANS_MESSAGE_NOT_HANDLED is returned, the hardware module 3900Sstevel@tonic-gate * is responsible for any action. 3910Sstevel@tonic-gate */ 3920Sstevel@tonic-gate enum kbtrans_message_response 3930Sstevel@tonic-gate kbtrans_streams_message(struct kbtrans *upper, register mblk_t *mp) 3940Sstevel@tonic-gate { 3950Sstevel@tonic-gate queue_t *q = upper->kbtrans_streams_readq; 3960Sstevel@tonic-gate enum kbtrans_message_response ret; 3970Sstevel@tonic-gate 3980Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, (upper, 3990Sstevel@tonic-gate "kbtrans_streams_message entering")); 4000Sstevel@tonic-gate /* 4010Sstevel@tonic-gate * Process M_FLUSH, and some M_IOCTL, messages here; pass 4020Sstevel@tonic-gate * everything else down. 4030Sstevel@tonic-gate */ 4040Sstevel@tonic-gate switch (mp->b_datap->db_type) { 4050Sstevel@tonic-gate 4060Sstevel@tonic-gate case M_IOCTL: 4070Sstevel@tonic-gate ret = kbtrans_ioctl(upper, mp); 4080Sstevel@tonic-gate break; 4090Sstevel@tonic-gate 4100Sstevel@tonic-gate case M_FLUSH: 4110Sstevel@tonic-gate if (*mp->b_rptr & FLUSHW) 4120Sstevel@tonic-gate flushq(q, FLUSHDATA); 4130Sstevel@tonic-gate if (*mp->b_rptr & FLUSHR) 4140Sstevel@tonic-gate flushq(RD(q), FLUSHDATA); 4150Sstevel@tonic-gate /* 4160Sstevel@tonic-gate * White lie: we say we didn't handle the message, 4170Sstevel@tonic-gate * so that it gets handled by our client. 4180Sstevel@tonic-gate */ 4190Sstevel@tonic-gate ret = KBTRANS_MESSAGE_NOT_HANDLED; 4200Sstevel@tonic-gate break; 4210Sstevel@tonic-gate 4220Sstevel@tonic-gate default: 4230Sstevel@tonic-gate ret = KBTRANS_MESSAGE_NOT_HANDLED; 4240Sstevel@tonic-gate break; 4250Sstevel@tonic-gate 4260Sstevel@tonic-gate } 4270Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, (upper, 4280Sstevel@tonic-gate "kbtrans_streams_message exiting\n")); 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate return (ret); 4310Sstevel@tonic-gate } 4320Sstevel@tonic-gate 4330Sstevel@tonic-gate /* 4340Sstevel@tonic-gate * kbtrans_streams_key: 4350Sstevel@tonic-gate * When a key is pressed or released, the hardware module should 4360Sstevel@tonic-gate * call kbtrans, passing the key number and its new 4370Sstevel@tonic-gate * state. kbtrans is responsible for autorepeat handling; 4380Sstevel@tonic-gate * the hardware module should report only actual press/release 4390Sstevel@tonic-gate * events, suppressing any hardware-generated autorepeat. 4400Sstevel@tonic-gate */ 4410Sstevel@tonic-gate void 4420Sstevel@tonic-gate kbtrans_streams_key( 4430Sstevel@tonic-gate struct kbtrans *upper, 4440Sstevel@tonic-gate kbtrans_key_t key, 4450Sstevel@tonic-gate enum keystate state) 4460Sstevel@tonic-gate { 4470Sstevel@tonic-gate struct kbtrans_lower *lower; 4480Sstevel@tonic-gate struct keyboard *kp; 4490Sstevel@tonic-gate 4500Sstevel@tonic-gate lower = &upper->kbtrans_lower; 4510Sstevel@tonic-gate kp = lower->kbtrans_keyboard; 4520Sstevel@tonic-gate 4530Sstevel@tonic-gate if (upper->kbtrans_streams_abortable) { 4540Sstevel@tonic-gate switch (upper->kbtrans_streams_abort_state) { 4550Sstevel@tonic-gate case ABORT_NORMAL: 4560Sstevel@tonic-gate if (state != KEY_PRESSED) 4570Sstevel@tonic-gate break; 4580Sstevel@tonic-gate 4590Sstevel@tonic-gate if (key == (kbtrans_key_t)kp->k_abort1 || 4600Sstevel@tonic-gate key == (kbtrans_key_t)kp->k_abort1a) { 4610Sstevel@tonic-gate upper->kbtrans_streams_abort_state = 4620Sstevel@tonic-gate ABORT_ABORT1_RECEIVED; 4630Sstevel@tonic-gate upper->kbtrans_streams_abort1_key = key; 4640Sstevel@tonic-gate return; 4650Sstevel@tonic-gate } 466*3739Sqz150045 /* Shift key needs to be sent to upper immediately */ 4673505Sqz150045 if (key == (kbtrans_key_t)kp->k_newabort1 || 4683505Sqz150045 key == (kbtrans_key_t)kp->k_newabort1a) { 4693505Sqz150045 upper->kbtrans_streams_abort_state = 4703505Sqz150045 NEW_ABORT_ABORT1_RECEIVED; 4713505Sqz150045 upper->kbtrans_streams_new_abort1_key = key; 4723505Sqz150045 } 4730Sstevel@tonic-gate break; 4740Sstevel@tonic-gate case ABORT_ABORT1_RECEIVED: 4750Sstevel@tonic-gate upper->kbtrans_streams_abort_state = ABORT_NORMAL; 4760Sstevel@tonic-gate if (state == KEY_PRESSED && 4770Sstevel@tonic-gate key == (kbtrans_key_t)kp->k_abort2) { 4780Sstevel@tonic-gate abort_sequence_enter((char *)NULL); 4790Sstevel@tonic-gate return; 4800Sstevel@tonic-gate } else { 4810Sstevel@tonic-gate kbtrans_processkey(lower, 4820Sstevel@tonic-gate upper->kbtrans_streams_callback, 4830Sstevel@tonic-gate upper->kbtrans_streams_abort1_key, 4840Sstevel@tonic-gate KEY_PRESSED); 4850Sstevel@tonic-gate } 4863505Sqz150045 break; 4873505Sqz150045 case NEW_ABORT_ABORT1_RECEIVED: 4883505Sqz150045 upper->kbtrans_streams_abort_state = ABORT_NORMAL; 4893505Sqz150045 if (state == KEY_PRESSED && 4903505Sqz150045 key == (kbtrans_key_t)kp->k_newabort2) { 4913505Sqz150045 abort_sequence_enter((char *)NULL); 4923505Sqz150045 kbtrans_processkey(lower, 4933505Sqz150045 upper->kbtrans_streams_callback, 4943505Sqz150045 upper->kbtrans_streams_new_abort1_key, 495*3739Sqz150045 KEY_RELEASED); 496*3739Sqz150045 return; 4973505Sqz150045 } 4980Sstevel@tonic-gate } 4990Sstevel@tonic-gate } 5000Sstevel@tonic-gate 5010Sstevel@tonic-gate kbtrans_processkey(lower, upper->kbtrans_streams_callback, key, state); 5020Sstevel@tonic-gate } 5030Sstevel@tonic-gate 5040Sstevel@tonic-gate /* 5050Sstevel@tonic-gate * kbtrans_streams_set_keyboard: 5060Sstevel@tonic-gate * At any time after calling kbtrans_streams_init, the hardware 5070Sstevel@tonic-gate * module should make this call to report the id of the keyboard 5080Sstevel@tonic-gate * attached. id is the keyboard type, typically KB_SUN4, 5090Sstevel@tonic-gate * KB_PC, or KB_USB. 5100Sstevel@tonic-gate */ 5110Sstevel@tonic-gate void 5120Sstevel@tonic-gate kbtrans_streams_set_keyboard( 5130Sstevel@tonic-gate struct kbtrans *upper, 5140Sstevel@tonic-gate int id, 5150Sstevel@tonic-gate struct keyboard *k) 5160Sstevel@tonic-gate { 5170Sstevel@tonic-gate upper->kbtrans_lower.kbtrans_keyboard = k; 5180Sstevel@tonic-gate upper->kbtrans_streams_id = id; 5190Sstevel@tonic-gate } 5200Sstevel@tonic-gate 5210Sstevel@tonic-gate /* 5220Sstevel@tonic-gate * kbtrans_streams_has_reset: 5230Sstevel@tonic-gate * At any time between kbtrans_streams_init and kbtrans_streams_fini, 5240Sstevel@tonic-gate * the hardware module can call this routine to report that the 5250Sstevel@tonic-gate * keyboard has been reset, e.g. by being unplugged and reattached. 5260Sstevel@tonic-gate */ 5270Sstevel@tonic-gate /*ARGSUSED*/ 5280Sstevel@tonic-gate void 5290Sstevel@tonic-gate kbtrans_streams_has_reset(struct kbtrans *upper) 5300Sstevel@tonic-gate { 5310Sstevel@tonic-gate /* 5320Sstevel@tonic-gate * If this routine is implemented it should probably (a) 5330Sstevel@tonic-gate * simulate releases of all pressed keys and (b) call 5340Sstevel@tonic-gate * the hardware module to set the LEDs. 5350Sstevel@tonic-gate */ 5360Sstevel@tonic-gate } 5370Sstevel@tonic-gate 5380Sstevel@tonic-gate /* 5390Sstevel@tonic-gate * kbtrans_streams_enable: 5400Sstevel@tonic-gate * This is the routine that is called back when the the stream is ready 5410Sstevel@tonic-gate * to take messages. 5420Sstevel@tonic-gate */ 5430Sstevel@tonic-gate void 5440Sstevel@tonic-gate kbtrans_streams_enable(struct kbtrans *upper) 5450Sstevel@tonic-gate { 5460Sstevel@tonic-gate /* Set the LED's */ 5470Sstevel@tonic-gate kbtrans_setled(upper); 5480Sstevel@tonic-gate } 5490Sstevel@tonic-gate 5500Sstevel@tonic-gate /* 5511272Slq150181 * kbtrans_streams_setled(): 5521272Slq150181 * This is the routine that is called to only update the led state 5531272Slq150181 * in kbtrans. 5541272Slq150181 */ 5551272Slq150181 void 5561272Slq150181 kbtrans_streams_setled(struct kbtrans *upper, int led_state) 5571272Slq150181 { 5581272Slq150181 struct kbtrans_lower *lower; 5591272Slq150181 5601272Slq150181 lower = &upper->kbtrans_lower; 5611272Slq150181 lower->kbtrans_led_state = (uchar_t)led_state; 5621272Slq150181 5631272Slq150181 if (lower->kbtrans_led_state & LED_CAPS_LOCK) 5641272Slq150181 lower->kbtrans_togglemask |= CAPSMASK; 5651272Slq150181 if (lower->kbtrans_led_state & LED_NUM_LOCK) 5661272Slq150181 lower->kbtrans_togglemask |= NUMLOCKMASK; 5671272Slq150181 5681272Slq150181 #if defined(SCROLLMASK) 5691272Slq150181 if (lower->kbtrans_led_state & LED_SCROLL_LOCK) 5701272Slq150181 lower->kbtrans_togglemask |= SCROLLMASK; 5711272Slq150181 #endif 5721272Slq150181 5731272Slq150181 lower->kbtrans_shiftmask = lower->kbtrans_togglemask; 5741272Slq150181 5751272Slq150181 } 5761272Slq150181 5771272Slq150181 /* 5780Sstevel@tonic-gate * kbtrans_streams_set_queue: 5790Sstevel@tonic-gate * Set the overlying queue, to support multiplexors. 5800Sstevel@tonic-gate */ 5810Sstevel@tonic-gate void 5820Sstevel@tonic-gate kbtrans_streams_set_queue(struct kbtrans *upper, queue_t *q) 5830Sstevel@tonic-gate { 5840Sstevel@tonic-gate 5850Sstevel@tonic-gate upper->kbtrans_streams_readq = q; 5860Sstevel@tonic-gate } 5870Sstevel@tonic-gate 5880Sstevel@tonic-gate /* 5890Sstevel@tonic-gate * kbtrans_streams_get_queue: 5900Sstevel@tonic-gate * Return the overlying queue. 5910Sstevel@tonic-gate */ 5920Sstevel@tonic-gate queue_t * 5930Sstevel@tonic-gate kbtrans_streams_get_queue(struct kbtrans *upper) 5940Sstevel@tonic-gate { 5950Sstevel@tonic-gate return (upper->kbtrans_streams_readq); 5960Sstevel@tonic-gate } 5970Sstevel@tonic-gate 5980Sstevel@tonic-gate /* 5990Sstevel@tonic-gate * kbtrans_streams_untimeout 6000Sstevel@tonic-gate * Cancell all timeout 6010Sstevel@tonic-gate */ 6020Sstevel@tonic-gate void 6030Sstevel@tonic-gate kbtrans_streams_untimeout(struct kbtrans *upper) 6040Sstevel@tonic-gate { 6050Sstevel@tonic-gate /* clear all timeouts */ 6060Sstevel@tonic-gate if (upper->kbtrans_streams_bufcallid) { 6070Sstevel@tonic-gate qunbufcall(upper->kbtrans_streams_readq, 6080Sstevel@tonic-gate upper->kbtrans_streams_bufcallid); 6090Sstevel@tonic-gate upper->kbtrans_streams_bufcallid = 0; 6100Sstevel@tonic-gate } 6110Sstevel@tonic-gate if (upper->kbtrans_streams_rptid) { 6120Sstevel@tonic-gate (void) quntimeout(upper->kbtrans_streams_readq, 6130Sstevel@tonic-gate upper->kbtrans_streams_rptid); 6140Sstevel@tonic-gate upper->kbtrans_streams_rptid = 0; 6150Sstevel@tonic-gate } 6160Sstevel@tonic-gate } 6170Sstevel@tonic-gate 6180Sstevel@tonic-gate /* 6190Sstevel@tonic-gate * kbtrans_reioctl: 6200Sstevel@tonic-gate * This function is set up as call-back function should an ioctl fail 6210Sstevel@tonic-gate * to allocate required resources. 6220Sstevel@tonic-gate */ 6230Sstevel@tonic-gate static void 6240Sstevel@tonic-gate kbtrans_reioctl(void *arg) 6250Sstevel@tonic-gate { 6260Sstevel@tonic-gate struct kbtrans *upper = (struct kbtrans *)arg; 6270Sstevel@tonic-gate mblk_t *mp; 6280Sstevel@tonic-gate 6290Sstevel@tonic-gate upper->kbtrans_streams_bufcallid = 0; 6300Sstevel@tonic-gate 6310Sstevel@tonic-gate if ((mp = upper->kbtrans_streams_iocpending) != NULL) { 6320Sstevel@tonic-gate /* not pending any more */ 6330Sstevel@tonic-gate upper->kbtrans_streams_iocpending = NULL; 6340Sstevel@tonic-gate (void) kbtrans_ioctl(upper, mp); 6350Sstevel@tonic-gate } 6360Sstevel@tonic-gate } 6370Sstevel@tonic-gate 6380Sstevel@tonic-gate /* 6390Sstevel@tonic-gate * kbtrans_ioctl: 6400Sstevel@tonic-gate * process ioctls we recognize and own. Otherwise, pass it down. 6410Sstevel@tonic-gate */ 6420Sstevel@tonic-gate static enum kbtrans_message_response 6430Sstevel@tonic-gate kbtrans_ioctl(struct kbtrans *upper, register mblk_t *mp) 6440Sstevel@tonic-gate { 6450Sstevel@tonic-gate register struct iocblk *iocp; 6460Sstevel@tonic-gate register short new_translate; 6470Sstevel@tonic-gate register Vuid_addr_probe *addr_probe; 6480Sstevel@tonic-gate register short *addr_ptr; 6490Sstevel@tonic-gate size_t ioctlrespsize; 6500Sstevel@tonic-gate int err = 0; 6510Sstevel@tonic-gate struct kbtrans_lower *lower; 6520Sstevel@tonic-gate mblk_t *datap; 6530Sstevel@tonic-gate int translate; 6540Sstevel@tonic-gate 6550Sstevel@tonic-gate static int kiocgetkey, kiocsetkey; 6560Sstevel@tonic-gate 6570Sstevel@tonic-gate lower = &upper->kbtrans_lower; 6580Sstevel@tonic-gate 6590Sstevel@tonic-gate iocp = (struct iocblk *)mp->b_rptr; 6600Sstevel@tonic-gate 6610Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, 6620Sstevel@tonic-gate "kbtrans_ioctl: ioc_cmd 0x%x - ", iocp->ioc_cmd)); 6630Sstevel@tonic-gate switch (iocp->ioc_cmd) { 6640Sstevel@tonic-gate 6650Sstevel@tonic-gate case VUIDSFORMAT: 6660Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "VUIDSFORMAT\n")); 6670Sstevel@tonic-gate 6680Sstevel@tonic-gate err = miocpullup(mp, sizeof (int)); 6690Sstevel@tonic-gate if (err != 0) 6700Sstevel@tonic-gate break; 6710Sstevel@tonic-gate new_translate = (*(int *)mp->b_cont->b_rptr == VUID_NATIVE) ? 6720Sstevel@tonic-gate TR_ASCII : TR_EVENT; 6730Sstevel@tonic-gate 6740Sstevel@tonic-gate if (new_translate == upper->kbtrans_streams_translate_mode) 6750Sstevel@tonic-gate break; 6760Sstevel@tonic-gate upper->kbtrans_streams_translate_mode = new_translate; 6770Sstevel@tonic-gate 6780Sstevel@tonic-gate kbtrans_set_translation_callback(upper); 6790Sstevel@tonic-gate 6800Sstevel@tonic-gate kbtrans_flush(upper); 6810Sstevel@tonic-gate break; 6820Sstevel@tonic-gate 6830Sstevel@tonic-gate case KIOCTRANS: 6840Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "KIOCTRANS\n")); 6850Sstevel@tonic-gate err = miocpullup(mp, sizeof (int)); 6860Sstevel@tonic-gate if (err != 0) 6870Sstevel@tonic-gate break; 6880Sstevel@tonic-gate new_translate = *(int *)mp->b_cont->b_rptr; 6890Sstevel@tonic-gate if (new_translate == upper->kbtrans_streams_translate_mode) 6900Sstevel@tonic-gate break; 6910Sstevel@tonic-gate upper->kbtrans_streams_translate_mode = new_translate; 6920Sstevel@tonic-gate kbtrans_set_translation_callback(upper); 6930Sstevel@tonic-gate 6940Sstevel@tonic-gate kbtrans_flush(upper); 6950Sstevel@tonic-gate break; 6960Sstevel@tonic-gate 6970Sstevel@tonic-gate case KIOCSLED: 6980Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "KIOCSLED\n")); 6990Sstevel@tonic-gate 7000Sstevel@tonic-gate err = miocpullup(mp, sizeof (uchar_t)); 7010Sstevel@tonic-gate if (err != 0) 7020Sstevel@tonic-gate break; 7030Sstevel@tonic-gate lower->kbtrans_led_state = *(uchar_t *)mp->b_cont->b_rptr; 7040Sstevel@tonic-gate 7050Sstevel@tonic-gate kbtrans_setled(upper); 7060Sstevel@tonic-gate break; 7070Sstevel@tonic-gate 7080Sstevel@tonic-gate case KIOCGLED: 7090Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "KIOCGLED\n")); 7100Sstevel@tonic-gate if ((datap = allocb(sizeof (uchar_t), BPRI_HI)) == NULL) { 7110Sstevel@tonic-gate ioctlrespsize = sizeof (int); 7120Sstevel@tonic-gate goto allocfailure; 7130Sstevel@tonic-gate } 7140Sstevel@tonic-gate 7150Sstevel@tonic-gate *(uchar_t *)datap->b_wptr = lower->kbtrans_led_state; 7160Sstevel@tonic-gate datap->b_wptr += sizeof (uchar_t); 7170Sstevel@tonic-gate if (mp->b_cont) 7180Sstevel@tonic-gate freemsg(mp->b_cont); 7190Sstevel@tonic-gate mp->b_cont = datap; 7200Sstevel@tonic-gate iocp->ioc_count = sizeof (uchar_t); 7210Sstevel@tonic-gate break; 7220Sstevel@tonic-gate 7230Sstevel@tonic-gate case VUIDGFORMAT: 7240Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "VUIDGFORMAT\n")); 7250Sstevel@tonic-gate if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL) { 7260Sstevel@tonic-gate ioctlrespsize = sizeof (int); 7270Sstevel@tonic-gate goto allocfailure; 7280Sstevel@tonic-gate } 7290Sstevel@tonic-gate *(int *)datap->b_wptr = 7300Sstevel@tonic-gate (upper->kbtrans_streams_translate_mode == TR_EVENT || 7310Sstevel@tonic-gate upper->kbtrans_streams_translate_mode == TR_UNTRANS_EVENT) ? 7320Sstevel@tonic-gate VUID_FIRM_EVENT: VUID_NATIVE; 7330Sstevel@tonic-gate datap->b_wptr += sizeof (int); 7340Sstevel@tonic-gate if (mp->b_cont) /* free msg to prevent memory leak */ 7350Sstevel@tonic-gate freemsg(mp->b_cont); 7360Sstevel@tonic-gate mp->b_cont = datap; 7370Sstevel@tonic-gate iocp->ioc_count = sizeof (int); 7380Sstevel@tonic-gate break; 7390Sstevel@tonic-gate 7400Sstevel@tonic-gate case KIOCGTRANS: 7410Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "KIOCGTRANS\n")); 7420Sstevel@tonic-gate if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL) { 7430Sstevel@tonic-gate ioctlrespsize = sizeof (int); 7440Sstevel@tonic-gate goto allocfailure; 7450Sstevel@tonic-gate } 7460Sstevel@tonic-gate *(int *)datap->b_wptr = upper->kbtrans_streams_translate_mode; 7470Sstevel@tonic-gate datap->b_wptr += sizeof (int); 7480Sstevel@tonic-gate if (mp->b_cont) /* free msg to prevent memory leak */ 7490Sstevel@tonic-gate freemsg(mp->b_cont); 7500Sstevel@tonic-gate mp->b_cont = datap; 7510Sstevel@tonic-gate iocp->ioc_count = sizeof (int); 7520Sstevel@tonic-gate break; 7530Sstevel@tonic-gate 7540Sstevel@tonic-gate case VUIDSADDR: 7550Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "VUIDSADDR\n")); 7560Sstevel@tonic-gate 7570Sstevel@tonic-gate err = miocpullup(mp, sizeof (Vuid_addr_probe)); 7580Sstevel@tonic-gate if (err != 0) 7590Sstevel@tonic-gate break; 7600Sstevel@tonic-gate addr_probe = (Vuid_addr_probe *)mp->b_cont->b_rptr; 7610Sstevel@tonic-gate switch (addr_probe->base) { 7620Sstevel@tonic-gate 7630Sstevel@tonic-gate case ASCII_FIRST: 7640Sstevel@tonic-gate addr_ptr = &upper->kbtrans_streams_vuid_addr.ascii; 7650Sstevel@tonic-gate break; 7660Sstevel@tonic-gate 7670Sstevel@tonic-gate case TOP_FIRST: 7680Sstevel@tonic-gate addr_ptr = &upper->kbtrans_streams_vuid_addr.top; 7690Sstevel@tonic-gate break; 7700Sstevel@tonic-gate 7710Sstevel@tonic-gate case VKEY_FIRST: 7720Sstevel@tonic-gate addr_ptr = &upper->kbtrans_streams_vuid_addr.vkey; 7730Sstevel@tonic-gate break; 7740Sstevel@tonic-gate 7750Sstevel@tonic-gate default: 7760Sstevel@tonic-gate err = ENODEV; 7770Sstevel@tonic-gate } 7780Sstevel@tonic-gate 7790Sstevel@tonic-gate if ((err == 0) && (*addr_ptr != addr_probe->data.next)) { 7800Sstevel@tonic-gate *addr_ptr = addr_probe->data.next; 7810Sstevel@tonic-gate kbtrans_flush(upper); 7820Sstevel@tonic-gate } 7830Sstevel@tonic-gate break; 7840Sstevel@tonic-gate 7850Sstevel@tonic-gate case VUIDGADDR: 7860Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "VUIDGADDR\n")); 7870Sstevel@tonic-gate 7880Sstevel@tonic-gate err = miocpullup(mp, sizeof (Vuid_addr_probe)); 7890Sstevel@tonic-gate if (err != 0) 7900Sstevel@tonic-gate break; 7910Sstevel@tonic-gate addr_probe = (Vuid_addr_probe *)mp->b_cont->b_rptr; 7920Sstevel@tonic-gate switch (addr_probe->base) { 7930Sstevel@tonic-gate 7940Sstevel@tonic-gate case ASCII_FIRST: 7950Sstevel@tonic-gate addr_probe->data.current = 7960Sstevel@tonic-gate upper->kbtrans_streams_vuid_addr.ascii; 7970Sstevel@tonic-gate break; 7980Sstevel@tonic-gate 7990Sstevel@tonic-gate case TOP_FIRST: 8000Sstevel@tonic-gate addr_probe->data.current = 8010Sstevel@tonic-gate upper->kbtrans_streams_vuid_addr.top; 8020Sstevel@tonic-gate break; 8030Sstevel@tonic-gate 8040Sstevel@tonic-gate case VKEY_FIRST: 8050Sstevel@tonic-gate addr_probe->data.current = 8060Sstevel@tonic-gate upper->kbtrans_streams_vuid_addr.vkey; 8070Sstevel@tonic-gate break; 8080Sstevel@tonic-gate 8090Sstevel@tonic-gate default: 8100Sstevel@tonic-gate err = ENODEV; 8110Sstevel@tonic-gate } 8120Sstevel@tonic-gate break; 8130Sstevel@tonic-gate 8140Sstevel@tonic-gate case KIOCTRANSABLE: 8150Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "KIOCTRANSABLE\n")); 8160Sstevel@tonic-gate 8170Sstevel@tonic-gate err = miocpullup(mp, sizeof (int)); 8180Sstevel@tonic-gate if (err != 0) 8190Sstevel@tonic-gate break; 8200Sstevel@tonic-gate /* 8210Sstevel@tonic-gate * called during console setup in kbconfig() 8220Sstevel@tonic-gate * If set to false, means we are a serial keyboard, 8230Sstevel@tonic-gate * and we should pass all data up without modification. 8240Sstevel@tonic-gate */ 8250Sstevel@tonic-gate translate = *(int *)mp->b_cont->b_rptr; 8260Sstevel@tonic-gate if (upper->kbtrans_streams_translatable != translate) 8270Sstevel@tonic-gate upper->kbtrans_streams_translatable = translate; 8280Sstevel@tonic-gate 8290Sstevel@tonic-gate if (translate != TR_CAN) 8300Sstevel@tonic-gate DPRINTF(PRINT_L4, PRINT_MASK_ALL, (upper, 8310Sstevel@tonic-gate "Cannot translate keyboard using tables.\n")); 8320Sstevel@tonic-gate break; 8330Sstevel@tonic-gate 8340Sstevel@tonic-gate case KIOCGTRANSABLE: 8350Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "KIOCGTRANSABLE\n")); 8360Sstevel@tonic-gate if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL) { 8370Sstevel@tonic-gate ioctlrespsize = sizeof (int); 8380Sstevel@tonic-gate goto allocfailure; 8390Sstevel@tonic-gate } 8400Sstevel@tonic-gate *(int *)datap->b_wptr = upper->kbtrans_streams_translatable; 8410Sstevel@tonic-gate datap->b_wptr += sizeof (int); 8420Sstevel@tonic-gate if (mp->b_cont) /* free msg to prevent memory leak */ 8430Sstevel@tonic-gate freemsg(mp->b_cont); 8440Sstevel@tonic-gate mp->b_cont = datap; 8450Sstevel@tonic-gate iocp->ioc_count = sizeof (int); 8460Sstevel@tonic-gate break; 8470Sstevel@tonic-gate 8480Sstevel@tonic-gate case KIOCSCOMPAT: 8490Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "KIOCSCOMPAT\n")); 8500Sstevel@tonic-gate 8510Sstevel@tonic-gate err = miocpullup(mp, sizeof (int)); 8520Sstevel@tonic-gate if (err != 0) 8530Sstevel@tonic-gate break; 8540Sstevel@tonic-gate lower->kbtrans_compat = *(int *)mp->b_cont->b_rptr; 8550Sstevel@tonic-gate break; 8560Sstevel@tonic-gate 8570Sstevel@tonic-gate case KIOCGCOMPAT: 8580Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "KIOCGCOMPAT\n")); 8590Sstevel@tonic-gate if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL) { 8600Sstevel@tonic-gate ioctlrespsize = sizeof (int); 8610Sstevel@tonic-gate goto allocfailure; 8620Sstevel@tonic-gate } 8630Sstevel@tonic-gate *(int *)datap->b_wptr = lower->kbtrans_compat; 8640Sstevel@tonic-gate datap->b_wptr += sizeof (int); 8650Sstevel@tonic-gate if (mp->b_cont) /* free msg to prevent memory leak */ 8660Sstevel@tonic-gate freemsg(mp->b_cont); 8670Sstevel@tonic-gate mp->b_cont = datap; 8680Sstevel@tonic-gate iocp->ioc_count = sizeof (int); 8690Sstevel@tonic-gate break; 8700Sstevel@tonic-gate 8710Sstevel@tonic-gate case KIOCSETKEY: 8720Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "KIOCSETKEY %d\n", 8730Sstevel@tonic-gate kiocsetkey++)); 8740Sstevel@tonic-gate err = miocpullup(mp, sizeof (struct kiockey)); 8750Sstevel@tonic-gate if (err != 0) 8760Sstevel@tonic-gate break; 8770Sstevel@tonic-gate err = kbtrans_setkey(&upper->kbtrans_lower, 8780Sstevel@tonic-gate (struct kiockey *)mp->b_cont->b_rptr, iocp->ioc_cr); 8790Sstevel@tonic-gate /* 8800Sstevel@tonic-gate * Since this only affects any subsequent key presses, 8810Sstevel@tonic-gate * don't flush soft state. One might want to 8820Sstevel@tonic-gate * toggle the keytable entries dynamically. 8830Sstevel@tonic-gate */ 8840Sstevel@tonic-gate break; 8850Sstevel@tonic-gate 8860Sstevel@tonic-gate case KIOCGETKEY: 8870Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "KIOCGETKEY %d\n", 8880Sstevel@tonic-gate kiocgetkey++)); 8890Sstevel@tonic-gate err = miocpullup(mp, sizeof (struct kiockey)); 8900Sstevel@tonic-gate if (err != 0) 8910Sstevel@tonic-gate break; 8920Sstevel@tonic-gate err = kbtrans_getkey(&upper->kbtrans_lower, 8930Sstevel@tonic-gate (struct kiockey *)mp->b_cont->b_rptr); 8940Sstevel@tonic-gate break; 8950Sstevel@tonic-gate 8960Sstevel@tonic-gate case KIOCSKEY: 8970Sstevel@tonic-gate err = miocpullup(mp, sizeof (struct kiockeymap)); 8980Sstevel@tonic-gate if (err != 0) 8990Sstevel@tonic-gate break; 9000Sstevel@tonic-gate err = kbtrans_skey(&upper->kbtrans_lower, 9010Sstevel@tonic-gate (struct kiockeymap *)mp->b_cont->b_rptr, iocp->ioc_cr); 9020Sstevel@tonic-gate /* 9030Sstevel@tonic-gate * Since this only affects any subsequent key presses, 9040Sstevel@tonic-gate * don't flush soft state. One might want to 9050Sstevel@tonic-gate * toggle the keytable entries dynamically. 9060Sstevel@tonic-gate */ 9070Sstevel@tonic-gate break; 9080Sstevel@tonic-gate 9090Sstevel@tonic-gate case KIOCGKEY: 9100Sstevel@tonic-gate err = miocpullup(mp, sizeof (struct kiockeymap)); 9110Sstevel@tonic-gate if (err != 0) 9120Sstevel@tonic-gate break; 9130Sstevel@tonic-gate err = kbtrans_gkey(&upper->kbtrans_lower, 9140Sstevel@tonic-gate (struct kiockeymap *)mp->b_cont->b_rptr); 9150Sstevel@tonic-gate break; 9160Sstevel@tonic-gate 9170Sstevel@tonic-gate case KIOCSDIRECT: 9180Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "KIOCSDIRECT\n")); 9190Sstevel@tonic-gate kbtrans_flush(upper); 9200Sstevel@tonic-gate break; 9210Sstevel@tonic-gate 9220Sstevel@tonic-gate case KIOCGDIRECT: 9230Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "KIOCSGDIRECT\n")); 9240Sstevel@tonic-gate if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL) { 9250Sstevel@tonic-gate ioctlrespsize = sizeof (int); 9260Sstevel@tonic-gate goto allocfailure; 9270Sstevel@tonic-gate } 9280Sstevel@tonic-gate *(int *)datap->b_wptr = 1; /* always direct */ 9290Sstevel@tonic-gate datap->b_wptr += sizeof (int); 9300Sstevel@tonic-gate if (mp->b_cont) /* free msg to prevent memory leak */ 9310Sstevel@tonic-gate freemsg(mp->b_cont); 9320Sstevel@tonic-gate mp->b_cont = datap; 9330Sstevel@tonic-gate iocp->ioc_count = sizeof (int); 9340Sstevel@tonic-gate break; 9350Sstevel@tonic-gate 9360Sstevel@tonic-gate case KIOCTYPE: 9370Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "KIOCTYPE\n")); 9380Sstevel@tonic-gate if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL) { 9390Sstevel@tonic-gate ioctlrespsize = sizeof (int); 9400Sstevel@tonic-gate goto allocfailure; 9410Sstevel@tonic-gate } 9420Sstevel@tonic-gate *(int *)datap->b_wptr = upper->kbtrans_streams_id; 9430Sstevel@tonic-gate datap->b_wptr += sizeof (int); 9440Sstevel@tonic-gate if (mp->b_cont) /* free msg to prevent memory leak */ 9450Sstevel@tonic-gate freemsg(mp->b_cont); 9460Sstevel@tonic-gate mp->b_cont = datap; 9470Sstevel@tonic-gate iocp->ioc_count = sizeof (int); 9480Sstevel@tonic-gate break; 9490Sstevel@tonic-gate 9500Sstevel@tonic-gate case CONSSETABORTENABLE: 9510Sstevel@tonic-gate /* 9520Sstevel@tonic-gate * Peek as it goes by; must be a TRANSPARENT ioctl. 9530Sstevel@tonic-gate */ 9540Sstevel@tonic-gate if (iocp->ioc_count != TRANSPARENT) { 9550Sstevel@tonic-gate err = EINVAL; 9560Sstevel@tonic-gate break; 9570Sstevel@tonic-gate } 9580Sstevel@tonic-gate 9590Sstevel@tonic-gate upper->kbtrans_streams_abortable = 9600Sstevel@tonic-gate (boolean_t)*(intptr_t *)mp->b_cont->b_rptr; 9610Sstevel@tonic-gate 9620Sstevel@tonic-gate /* 9630Sstevel@tonic-gate * Let the hardware module see it too. 9640Sstevel@tonic-gate */ 9650Sstevel@tonic-gate return (KBTRANS_MESSAGE_NOT_HANDLED); 9660Sstevel@tonic-gate 9670Sstevel@tonic-gate case KIOCGRPTDELAY: 9680Sstevel@tonic-gate /* 9690Sstevel@tonic-gate * Report the autorepeat delay, unit in millisecond 9700Sstevel@tonic-gate */ 9710Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "KIOCGRPTDELAY\n")); 9720Sstevel@tonic-gate if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL) { 9730Sstevel@tonic-gate ioctlrespsize = sizeof (int); 9740Sstevel@tonic-gate goto allocfailure; 9750Sstevel@tonic-gate } 9760Sstevel@tonic-gate *(int *)datap->b_wptr = TICK_TO_MSEC(kbtrans_repeat_delay); 9770Sstevel@tonic-gate datap->b_wptr += sizeof (int); 9780Sstevel@tonic-gate 9790Sstevel@tonic-gate /* free msg to prevent memory leak */ 9800Sstevel@tonic-gate if (mp->b_cont != NULL) 9810Sstevel@tonic-gate freemsg(mp->b_cont); 9820Sstevel@tonic-gate mp->b_cont = datap; 9830Sstevel@tonic-gate iocp->ioc_count = sizeof (int); 9840Sstevel@tonic-gate break; 9850Sstevel@tonic-gate 9860Sstevel@tonic-gate case KIOCSRPTDELAY: 9870Sstevel@tonic-gate /* 9880Sstevel@tonic-gate * Set the autorepeat delay 9890Sstevel@tonic-gate */ 9900Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "KIOCSRPTDELAY\n")); 9910Sstevel@tonic-gate err = miocpullup(mp, sizeof (int)); 9920Sstevel@tonic-gate 9930Sstevel@tonic-gate if (err != 0) 9940Sstevel@tonic-gate break; 9950Sstevel@tonic-gate 9960Sstevel@tonic-gate /* validate the input */ 9970Sstevel@tonic-gate if (*(int *)mp->b_cont->b_rptr < KIOCRPTDELAY_MIN) { 9980Sstevel@tonic-gate err = EINVAL; 9990Sstevel@tonic-gate break; 10000Sstevel@tonic-gate } 10010Sstevel@tonic-gate kbtrans_repeat_delay = MSEC_TO_TICK(*(int *)mp->b_cont->b_rptr); 10020Sstevel@tonic-gate if (kbtrans_repeat_delay <= 0) 10030Sstevel@tonic-gate kbtrans_repeat_delay = 1; 10040Sstevel@tonic-gate break; 10050Sstevel@tonic-gate 10060Sstevel@tonic-gate case KIOCGRPTRATE: 10070Sstevel@tonic-gate /* 10080Sstevel@tonic-gate * Report the autorepeat rate 10090Sstevel@tonic-gate */ 10100Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "KIOCGRPTRATE\n")); 10110Sstevel@tonic-gate if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL) { 10120Sstevel@tonic-gate ioctlrespsize = sizeof (int); 10130Sstevel@tonic-gate goto allocfailure; 10140Sstevel@tonic-gate } 10150Sstevel@tonic-gate *(int *)datap->b_wptr = TICK_TO_MSEC(kbtrans_repeat_rate); 10160Sstevel@tonic-gate datap->b_wptr += sizeof (int); 10170Sstevel@tonic-gate 10180Sstevel@tonic-gate /* free msg to prevent memory leak */ 10190Sstevel@tonic-gate if (mp->b_cont != NULL) 10200Sstevel@tonic-gate freemsg(mp->b_cont); 10210Sstevel@tonic-gate mp->b_cont = datap; 10220Sstevel@tonic-gate iocp->ioc_count = sizeof (int); 10230Sstevel@tonic-gate break; 10240Sstevel@tonic-gate 10250Sstevel@tonic-gate case KIOCSRPTRATE: 10260Sstevel@tonic-gate /* 10270Sstevel@tonic-gate * Set the autorepeat rate 10280Sstevel@tonic-gate */ 10290Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "KIOCSRPTRATE\n")); 10300Sstevel@tonic-gate err = miocpullup(mp, sizeof (int)); 10310Sstevel@tonic-gate 10320Sstevel@tonic-gate if (err != 0) 10330Sstevel@tonic-gate break; 10340Sstevel@tonic-gate 10350Sstevel@tonic-gate /* validate the input */ 10360Sstevel@tonic-gate if (*(int *)mp->b_cont->b_rptr < KIOCRPTRATE_MIN) { 10370Sstevel@tonic-gate err = EINVAL; 10380Sstevel@tonic-gate break; 10390Sstevel@tonic-gate } 10400Sstevel@tonic-gate kbtrans_repeat_rate = MSEC_TO_TICK(*(int *)mp->b_cont->b_rptr); 10410Sstevel@tonic-gate if (kbtrans_repeat_rate <= 0) 10420Sstevel@tonic-gate kbtrans_repeat_rate = 1; 10430Sstevel@tonic-gate break; 10440Sstevel@tonic-gate 10450Sstevel@tonic-gate default: 10460Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (upper, "unknown\n")); 10470Sstevel@tonic-gate return (KBTRANS_MESSAGE_NOT_HANDLED); 10480Sstevel@tonic-gate } /* end switch */ 10490Sstevel@tonic-gate 10500Sstevel@tonic-gate if (err != 0) { 10510Sstevel@tonic-gate iocp->ioc_rval = 0; 10520Sstevel@tonic-gate iocp->ioc_error = err; 10530Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK; 10540Sstevel@tonic-gate } else { 10550Sstevel@tonic-gate iocp->ioc_rval = 0; 10560Sstevel@tonic-gate iocp->ioc_error = 0; /* brain rot */ 10570Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 10580Sstevel@tonic-gate } 10590Sstevel@tonic-gate putnext(upper->kbtrans_streams_readq, mp); 10600Sstevel@tonic-gate 10610Sstevel@tonic-gate return (KBTRANS_MESSAGE_HANDLED); 10620Sstevel@tonic-gate 10630Sstevel@tonic-gate allocfailure: 10640Sstevel@tonic-gate /* 10650Sstevel@tonic-gate * We needed to allocate something to handle this "ioctl", but 10660Sstevel@tonic-gate * couldn't; save this "ioctl" and arrange to get called back when 10670Sstevel@tonic-gate * it's more likely that we can get what we need. 10680Sstevel@tonic-gate * If there's already one being saved, throw it out, since it 10690Sstevel@tonic-gate * must have timed out. 10700Sstevel@tonic-gate */ 10710Sstevel@tonic-gate if (upper->kbtrans_streams_iocpending != NULL) 10720Sstevel@tonic-gate freemsg(upper->kbtrans_streams_iocpending); 10730Sstevel@tonic-gate upper->kbtrans_streams_iocpending = mp; 10740Sstevel@tonic-gate if (upper->kbtrans_streams_bufcallid) { 10750Sstevel@tonic-gate qunbufcall(upper->kbtrans_streams_readq, 10760Sstevel@tonic-gate upper->kbtrans_streams_bufcallid); 10770Sstevel@tonic-gate } 10780Sstevel@tonic-gate upper->kbtrans_streams_bufcallid = 10790Sstevel@tonic-gate qbufcall(upper->kbtrans_streams_readq, ioctlrespsize, BPRI_HI, 10800Sstevel@tonic-gate kbtrans_reioctl, upper); 10810Sstevel@tonic-gate /* 10820Sstevel@tonic-gate * This is a white lie... we *will* handle it, eventually. 10830Sstevel@tonic-gate */ 10840Sstevel@tonic-gate return (KBTRANS_MESSAGE_HANDLED); 10850Sstevel@tonic-gate } 10860Sstevel@tonic-gate 10870Sstevel@tonic-gate /* 10880Sstevel@tonic-gate * kbtrans_flush: 10890Sstevel@tonic-gate * Flush data upstream 10900Sstevel@tonic-gate */ 10910Sstevel@tonic-gate static void 10920Sstevel@tonic-gate kbtrans_flush(register struct kbtrans *upper) 10930Sstevel@tonic-gate { 10940Sstevel@tonic-gate register queue_t *q; 10950Sstevel@tonic-gate 10960Sstevel@tonic-gate /* Flush pending data already sent upstream */ 10970Sstevel@tonic-gate if ((q = upper->kbtrans_streams_readq) != NULL && q->q_next != NULL) 10980Sstevel@tonic-gate (void) putnextctl1(q, M_FLUSH, FLUSHR); 10990Sstevel@tonic-gate 11000Sstevel@tonic-gate /* Flush pending ups */ 11010Sstevel@tonic-gate bzero(upper->kbtrans_streams_downs, upper->kbtrans_streams_downs_bytes); 11020Sstevel@tonic-gate 11030Sstevel@tonic-gate kbtrans_cancelrpt(upper); 11040Sstevel@tonic-gate } 11050Sstevel@tonic-gate 11060Sstevel@tonic-gate /* 11070Sstevel@tonic-gate * kbtrans_setled: 11080Sstevel@tonic-gate * Update the keyboard LEDs to match the current keyboard state. 11090Sstevel@tonic-gate */ 11100Sstevel@tonic-gate static void 11110Sstevel@tonic-gate kbtrans_setled(struct kbtrans *upper) 11120Sstevel@tonic-gate { 11130Sstevel@tonic-gate upper->kbtrans_streams_hw_callbacks->kbtrans_streams_setled( 11140Sstevel@tonic-gate upper->kbtrans_streams_hw, 11150Sstevel@tonic-gate upper->kbtrans_lower.kbtrans_led_state); 11160Sstevel@tonic-gate } 11170Sstevel@tonic-gate 11180Sstevel@tonic-gate /* 11190Sstevel@tonic-gate * kbtrans_rpt: 11200Sstevel@tonic-gate * If a key is held down, this function is set up to be called 11210Sstevel@tonic-gate * after kbtrans_repeat_rate time elapses. 11220Sstevel@tonic-gate */ 11230Sstevel@tonic-gate static void 11240Sstevel@tonic-gate kbtrans_rpt(void *arg) 11250Sstevel@tonic-gate { 11260Sstevel@tonic-gate struct kbtrans *upper = arg; 11270Sstevel@tonic-gate struct kbtrans_lower *lower = &upper->kbtrans_lower; 11280Sstevel@tonic-gate 11290Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (NULL, 11300Sstevel@tonic-gate "kbtrans_rpt: repeat key %X\n", 11310Sstevel@tonic-gate lower->kbtrans_repeatkey)); 11320Sstevel@tonic-gate 11330Sstevel@tonic-gate upper->kbtrans_streams_rptid = 0; 11340Sstevel@tonic-gate 11350Sstevel@tonic-gate /* 11360Sstevel@tonic-gate * NB: polled code zaps kbtrans_repeatkey without cancelling 11370Sstevel@tonic-gate * timeout. 11380Sstevel@tonic-gate */ 11390Sstevel@tonic-gate if (lower->kbtrans_repeatkey != 0) { 11400Sstevel@tonic-gate kbtrans_keyreleased(upper, lower->kbtrans_repeatkey); 11410Sstevel@tonic-gate 11420Sstevel@tonic-gate kbtrans_processkey(lower, 11430Sstevel@tonic-gate upper->kbtrans_streams_callback, 11440Sstevel@tonic-gate lower->kbtrans_repeatkey, 11450Sstevel@tonic-gate KEY_PRESSED); 11460Sstevel@tonic-gate 11470Sstevel@tonic-gate upper->kbtrans_streams_rptid = 11480Sstevel@tonic-gate qtimeout(upper->kbtrans_streams_readq, kbtrans_rpt, 11490Sstevel@tonic-gate (caddr_t)upper, kbtrans_repeat_rate); 11500Sstevel@tonic-gate } 11510Sstevel@tonic-gate } 11520Sstevel@tonic-gate 11530Sstevel@tonic-gate /* 11540Sstevel@tonic-gate * kbtrans_cancelrpt: 11550Sstevel@tonic-gate * Cancel the repeating key 11560Sstevel@tonic-gate */ 11570Sstevel@tonic-gate static void 11580Sstevel@tonic-gate kbtrans_cancelrpt(struct kbtrans *upper) 11590Sstevel@tonic-gate { 11600Sstevel@tonic-gate upper->kbtrans_lower.kbtrans_repeatkey = 0; 11610Sstevel@tonic-gate 11620Sstevel@tonic-gate if (upper->kbtrans_streams_rptid != 0) { 11630Sstevel@tonic-gate (void) quntimeout(upper->kbtrans_streams_readq, 11640Sstevel@tonic-gate upper->kbtrans_streams_rptid); 11650Sstevel@tonic-gate upper->kbtrans_streams_rptid = 0; 11660Sstevel@tonic-gate } 11670Sstevel@tonic-gate } 11680Sstevel@tonic-gate 11690Sstevel@tonic-gate /* 11700Sstevel@tonic-gate * kbtrans_send_esc_event: 11710Sstevel@tonic-gate * Send character up stream. Used for the case of 11720Sstevel@tonic-gate * sending strings upstream. 11730Sstevel@tonic-gate */ 11740Sstevel@tonic-gate static void 11750Sstevel@tonic-gate kbtrans_send_esc_event(char c, register struct kbtrans *upper) 11760Sstevel@tonic-gate { 11770Sstevel@tonic-gate Firm_event fe; 11780Sstevel@tonic-gate 11790Sstevel@tonic-gate fe.id = c; 11800Sstevel@tonic-gate fe.value = 1; 11810Sstevel@tonic-gate fe.pair_type = FE_PAIR_NONE; 11820Sstevel@tonic-gate fe.pair = 0; 11830Sstevel@tonic-gate /* 11840Sstevel@tonic-gate * Pretend as if each cp pushed and released 11850Sstevel@tonic-gate * Calling kbtrans_queueevent avoids addr translation 11860Sstevel@tonic-gate * and pair base determination of kbtrans_keypressed. 11870Sstevel@tonic-gate */ 11880Sstevel@tonic-gate kbtrans_queueevent(upper, &fe); 11890Sstevel@tonic-gate fe.value = 0; 11900Sstevel@tonic-gate kbtrans_queueevent(upper, &fe); 11910Sstevel@tonic-gate } 11920Sstevel@tonic-gate 11930Sstevel@tonic-gate /* 11940Sstevel@tonic-gate * kbtrans_strsetwithdecimal: 11950Sstevel@tonic-gate * Used for expanding a function key to the ascii equivalent 11960Sstevel@tonic-gate */ 11970Sstevel@tonic-gate static char * 11980Sstevel@tonic-gate kbtrans_strsetwithdecimal(char *buf, uint_t val, uint_t maxdigs) 11990Sstevel@tonic-gate { 12000Sstevel@tonic-gate int hradix = 5; 12010Sstevel@tonic-gate char *bp; 12020Sstevel@tonic-gate int lowbit; 12030Sstevel@tonic-gate char *tab = "0123456789abcdef"; 12040Sstevel@tonic-gate 12050Sstevel@tonic-gate bp = buf + maxdigs; 12060Sstevel@tonic-gate *(--bp) = '\0'; 12070Sstevel@tonic-gate while (val) { 12080Sstevel@tonic-gate lowbit = val & 1; 12090Sstevel@tonic-gate val = (val >> 1); 12100Sstevel@tonic-gate *(--bp) = tab[val % hradix * 2 + lowbit]; 12110Sstevel@tonic-gate val /= hradix; 12120Sstevel@tonic-gate } 12130Sstevel@tonic-gate return (bp); 12140Sstevel@tonic-gate } 12150Sstevel@tonic-gate 12160Sstevel@tonic-gate /* 12170Sstevel@tonic-gate * kbtrans_keypressed: 12180Sstevel@tonic-gate * Modify Firm event to be sent up the stream 12190Sstevel@tonic-gate */ 12200Sstevel@tonic-gate static void 12210Sstevel@tonic-gate kbtrans_keypressed(struct kbtrans *upper, uchar_t key_station, 12220Sstevel@tonic-gate Firm_event *fe, ushort_t base) 12230Sstevel@tonic-gate { 12240Sstevel@tonic-gate 12250Sstevel@tonic-gate register short id_addr; 12260Sstevel@tonic-gate struct kbtrans_lower *lower = &upper->kbtrans_lower; 12270Sstevel@tonic-gate 12280Sstevel@tonic-gate /* Set pair values */ 12290Sstevel@tonic-gate if (fe->id < (ushort_t)VKEY_FIRST) { 12300Sstevel@tonic-gate /* 12310Sstevel@tonic-gate * If CTRLed, find the ID that would have been used had it 12320Sstevel@tonic-gate * not been CTRLed. 12330Sstevel@tonic-gate */ 12340Sstevel@tonic-gate if (lower->kbtrans_shiftmask & (CTRLMASK | CTLSMASK)) { 12350Sstevel@tonic-gate unsigned short *ke; 12360Sstevel@tonic-gate unsigned int mask; 12370Sstevel@tonic-gate 12380Sstevel@tonic-gate mask = lower->kbtrans_shiftmask & 12390Sstevel@tonic-gate ~(CTRLMASK | CTLSMASK | UPMASK); 12400Sstevel@tonic-gate 12410Sstevel@tonic-gate ke = kbtrans_find_entry(lower, mask, key_station); 12420Sstevel@tonic-gate if (ke == NULL) 12430Sstevel@tonic-gate return; 12440Sstevel@tonic-gate 12450Sstevel@tonic-gate base = *ke; 12460Sstevel@tonic-gate } 12470Sstevel@tonic-gate if (base != fe->id) { 12480Sstevel@tonic-gate fe->pair_type = FE_PAIR_SET; 12490Sstevel@tonic-gate fe->pair = (uchar_t)base; 12500Sstevel@tonic-gate 12510Sstevel@tonic-gate goto send; 12520Sstevel@tonic-gate } 12530Sstevel@tonic-gate } 12540Sstevel@tonic-gate fe->pair_type = FE_PAIR_NONE; 12550Sstevel@tonic-gate fe->pair = 0; 12560Sstevel@tonic-gate 12570Sstevel@tonic-gate send: 12580Sstevel@tonic-gate /* Adjust event id address for multiple keyboard/workstation support */ 12590Sstevel@tonic-gate switch (vuid_id_addr(fe->id)) { 12600Sstevel@tonic-gate case ASCII_FIRST: 12610Sstevel@tonic-gate id_addr = upper->kbtrans_streams_vuid_addr.ascii; 12620Sstevel@tonic-gate break; 12630Sstevel@tonic-gate case TOP_FIRST: 12640Sstevel@tonic-gate id_addr = upper->kbtrans_streams_vuid_addr.top; 12650Sstevel@tonic-gate break; 12660Sstevel@tonic-gate case VKEY_FIRST: 12670Sstevel@tonic-gate id_addr = upper->kbtrans_streams_vuid_addr.vkey; 12680Sstevel@tonic-gate break; 12690Sstevel@tonic-gate default: 12700Sstevel@tonic-gate id_addr = vuid_id_addr(fe->id); 12710Sstevel@tonic-gate break; 12720Sstevel@tonic-gate } 12730Sstevel@tonic-gate fe->id = vuid_id_offset(fe->id) | id_addr; 12740Sstevel@tonic-gate 12750Sstevel@tonic-gate kbtrans_queuepress(upper, key_station, fe); 12760Sstevel@tonic-gate } 12770Sstevel@tonic-gate 12780Sstevel@tonic-gate /* 12790Sstevel@tonic-gate * kbtrans_queuepress: 12800Sstevel@tonic-gate * Add keypress to the "downs" table 12810Sstevel@tonic-gate */ 12820Sstevel@tonic-gate static void 12830Sstevel@tonic-gate kbtrans_queuepress(struct kbtrans *upper, 12840Sstevel@tonic-gate uchar_t key_station, Firm_event *fe) 12850Sstevel@tonic-gate { 12860Sstevel@tonic-gate register struct key_event *ke, *ke_free; 12870Sstevel@tonic-gate register int i; 12880Sstevel@tonic-gate 12890Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (NULL, "kbtrans_queuepress:" 12900Sstevel@tonic-gate " key=%d", key_station)); 12910Sstevel@tonic-gate 12920Sstevel@tonic-gate ke_free = 0; 12930Sstevel@tonic-gate 12940Sstevel@tonic-gate /* Scan table of down key stations */ 12950Sstevel@tonic-gate 12960Sstevel@tonic-gate for (i = 0, ke = upper->kbtrans_streams_downs; 12970Sstevel@tonic-gate i < upper->kbtrans_streams_num_downs_entries; i++, ke++) { 12980Sstevel@tonic-gate 12990Sstevel@tonic-gate /* Keycode already down? */ 13000Sstevel@tonic-gate if (ke->key_station == key_station) { 13010Sstevel@tonic-gate 13020Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, 13030Sstevel@tonic-gate (NULL, "kbtrans: Double " 13040Sstevel@tonic-gate "entry in downs table (%d,%d)!\n", 13050Sstevel@tonic-gate key_station, i)); 13060Sstevel@tonic-gate 13070Sstevel@tonic-gate goto add_event; 13080Sstevel@tonic-gate } 13090Sstevel@tonic-gate 13100Sstevel@tonic-gate if (ke->key_station == 0) 13110Sstevel@tonic-gate ke_free = ke; 13120Sstevel@tonic-gate } 13130Sstevel@tonic-gate 13140Sstevel@tonic-gate if (ke_free) { 13150Sstevel@tonic-gate ke = ke_free; 13160Sstevel@tonic-gate goto add_event; 13170Sstevel@tonic-gate } 13180Sstevel@tonic-gate 13190Sstevel@tonic-gate ke = upper->kbtrans_streams_downs; 13200Sstevel@tonic-gate 13210Sstevel@tonic-gate add_event: 13220Sstevel@tonic-gate ke->key_station = key_station; 13230Sstevel@tonic-gate ke->event = *fe; 13240Sstevel@tonic-gate kbtrans_queueevent(upper, fe); 13250Sstevel@tonic-gate } 13260Sstevel@tonic-gate 13270Sstevel@tonic-gate /* 13280Sstevel@tonic-gate * kbtrans_keyreleased: 13290Sstevel@tonic-gate * Remove entry from the downs table 13300Sstevel@tonic-gate */ 13310Sstevel@tonic-gate static void 13320Sstevel@tonic-gate kbtrans_keyreleased(register struct kbtrans *upper, uchar_t key_station) 13330Sstevel@tonic-gate { 13340Sstevel@tonic-gate register struct key_event *ke; 13350Sstevel@tonic-gate register int i; 13360Sstevel@tonic-gate 13370Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (NULL, "RELEASE key=%d\n", 13380Sstevel@tonic-gate key_station)); 13390Sstevel@tonic-gate 13400Sstevel@tonic-gate if (upper->kbtrans_streams_translate_mode != TR_EVENT && 13410Sstevel@tonic-gate upper->kbtrans_streams_translate_mode != TR_UNTRANS_EVENT) { 13420Sstevel@tonic-gate 13430Sstevel@tonic-gate return; 13440Sstevel@tonic-gate } 13450Sstevel@tonic-gate 13460Sstevel@tonic-gate /* Scan table of down key stations */ 13470Sstevel@tonic-gate for (i = 0, ke = upper->kbtrans_streams_downs; 13480Sstevel@tonic-gate i < upper->kbtrans_streams_num_downs_entries; 13490Sstevel@tonic-gate i++, ke++) { 13500Sstevel@tonic-gate /* Found? */ 13510Sstevel@tonic-gate if (ke->key_station == key_station) { 13520Sstevel@tonic-gate ke->key_station = 0; 13530Sstevel@tonic-gate ke->event.value = 0; 13540Sstevel@tonic-gate kbtrans_queueevent(upper, &ke->event); 13550Sstevel@tonic-gate } 13560Sstevel@tonic-gate } 13570Sstevel@tonic-gate 13580Sstevel@tonic-gate /* 13590Sstevel@tonic-gate * Ignore if couldn't find because may be called twice 13600Sstevel@tonic-gate * for the same key station in the case of the kbtrans_rpt 13610Sstevel@tonic-gate * routine being called unnecessarily. 13620Sstevel@tonic-gate */ 13630Sstevel@tonic-gate } 13640Sstevel@tonic-gate 13650Sstevel@tonic-gate 13660Sstevel@tonic-gate /* 13670Sstevel@tonic-gate * kbtrans_putcode: 13680Sstevel@tonic-gate * Pass a keycode up the stream, if you can, otherwise throw it away. 13690Sstevel@tonic-gate */ 13700Sstevel@tonic-gate static void 13710Sstevel@tonic-gate kbtrans_putcode(register struct kbtrans *upper, uint_t code) 13720Sstevel@tonic-gate { 13730Sstevel@tonic-gate register mblk_t *bp; 13740Sstevel@tonic-gate 13750Sstevel@tonic-gate /* 13760Sstevel@tonic-gate * If we can't send it up, then we just drop it. 13770Sstevel@tonic-gate */ 13780Sstevel@tonic-gate if (!canputnext(upper->kbtrans_streams_readq)) { 13790Sstevel@tonic-gate 13800Sstevel@tonic-gate return; 13810Sstevel@tonic-gate } 13820Sstevel@tonic-gate 13830Sstevel@tonic-gate /* 13840Sstevel@tonic-gate * Allocate a messsage block to send up. 13850Sstevel@tonic-gate */ 13860Sstevel@tonic-gate if ((bp = allocb(sizeof (uint_t), BPRI_HI)) == NULL) { 13870Sstevel@tonic-gate 13880Sstevel@tonic-gate cmn_err(CE_WARN, "kbtrans_putcode: Can't allocate block\ 13890Sstevel@tonic-gate for keycode."); 13900Sstevel@tonic-gate 13910Sstevel@tonic-gate return; 13920Sstevel@tonic-gate } 13930Sstevel@tonic-gate 13940Sstevel@tonic-gate /* 13950Sstevel@tonic-gate * We will strip out any high order information here. 13960Sstevel@tonic-gate */ 13970Sstevel@tonic-gate /* NOTE the implicit cast here */ 13980Sstevel@tonic-gate *bp->b_wptr++ = (uchar_t)code; 13990Sstevel@tonic-gate 14000Sstevel@tonic-gate /* 14010Sstevel@tonic-gate * Send the message up. 14020Sstevel@tonic-gate */ 14030Sstevel@tonic-gate (void) putnext(upper->kbtrans_streams_readq, bp); 14040Sstevel@tonic-gate } 14050Sstevel@tonic-gate 14060Sstevel@tonic-gate 14070Sstevel@tonic-gate /* 14080Sstevel@tonic-gate * kbtrans_putbuf: 14090Sstevel@tonic-gate * Pass generated keycode sequence to upstream, if possible. 14100Sstevel@tonic-gate */ 14110Sstevel@tonic-gate static void 14120Sstevel@tonic-gate kbtrans_putbuf(char *buf, queue_t *q) 14130Sstevel@tonic-gate { 14140Sstevel@tonic-gate register mblk_t *bp; 14150Sstevel@tonic-gate 14160Sstevel@tonic-gate if (!canputnext(q)) { 14170Sstevel@tonic-gate cmn_err(CE_WARN, "kbtrans_putbuf: Can't put block for keycode"); 14180Sstevel@tonic-gate } else { 14190Sstevel@tonic-gate if ((bp = allocb((int)strlen(buf), BPRI_HI)) == NULL) { 14200Sstevel@tonic-gate cmn_err(CE_WARN, "kbtrans_putbuf: " 14210Sstevel@tonic-gate "Can't allocate block for keycode"); 14220Sstevel@tonic-gate } else { 14230Sstevel@tonic-gate while (*buf) { 14240Sstevel@tonic-gate *bp->b_wptr++ = *buf; 14250Sstevel@tonic-gate buf++; 14260Sstevel@tonic-gate } 14270Sstevel@tonic-gate putnext(q, bp); 14280Sstevel@tonic-gate } 14290Sstevel@tonic-gate } 14300Sstevel@tonic-gate } 14310Sstevel@tonic-gate 14320Sstevel@tonic-gate /* 14330Sstevel@tonic-gate * kbtrans_queueevent: 14340Sstevel@tonic-gate * Pass a VUID "firm event" up the stream, if you can. 14350Sstevel@tonic-gate */ 14360Sstevel@tonic-gate static void 14370Sstevel@tonic-gate kbtrans_queueevent(struct kbtrans *upper, Firm_event *fe) 14380Sstevel@tonic-gate { 14390Sstevel@tonic-gate register queue_t *q; 14400Sstevel@tonic-gate register mblk_t *bp; 14410Sstevel@tonic-gate 14420Sstevel@tonic-gate if ((q = upper->kbtrans_streams_readq) == NULL) 14430Sstevel@tonic-gate 14440Sstevel@tonic-gate return; 14450Sstevel@tonic-gate 14460Sstevel@tonic-gate if (!canputnext(q)) { 14470Sstevel@tonic-gate if (kbtrans_overflow_msg) { 14480Sstevel@tonic-gate DPRINTF(PRINT_L2, PRINT_MASK_ALL, (NULL, 14490Sstevel@tonic-gate "kbtrans: Buffer flushed when overflowed.")); 14500Sstevel@tonic-gate } 14510Sstevel@tonic-gate 14520Sstevel@tonic-gate kbtrans_flush(upper); 14530Sstevel@tonic-gate upper->kbtrans_overflow_cnt++; 14540Sstevel@tonic-gate } else { 14550Sstevel@tonic-gate if ((bp = allocb(sizeof (Firm_event), BPRI_HI)) == NULL) { 14560Sstevel@tonic-gate cmn_err(CE_WARN, "kbtrans_queueevent: Can't allocate \ 14570Sstevel@tonic-gate block for event."); 14580Sstevel@tonic-gate } else { 14590Sstevel@tonic-gate uniqtime32(&fe->time); 14600Sstevel@tonic-gate *(Firm_event *)bp->b_wptr = *fe; 14610Sstevel@tonic-gate bp->b_wptr += sizeof (Firm_event); 14620Sstevel@tonic-gate (void) putnext(q, bp); 14630Sstevel@tonic-gate 14640Sstevel@tonic-gate 14650Sstevel@tonic-gate } 14660Sstevel@tonic-gate } 14670Sstevel@tonic-gate } 14680Sstevel@tonic-gate 14690Sstevel@tonic-gate /* 14700Sstevel@tonic-gate * kbtrans_set_translation_callback: 14710Sstevel@tonic-gate * This code sets the translation_callback pointer based on the 14720Sstevel@tonic-gate * translation mode. 14730Sstevel@tonic-gate */ 14740Sstevel@tonic-gate static void 14750Sstevel@tonic-gate kbtrans_set_translation_callback(register struct kbtrans *upper) 14760Sstevel@tonic-gate { 14770Sstevel@tonic-gate switch (upper->kbtrans_streams_translate_mode) { 14780Sstevel@tonic-gate 14790Sstevel@tonic-gate default: 14800Sstevel@tonic-gate case TR_ASCII: 14810Sstevel@tonic-gate upper->kbtrans_streams_callback = &ascii_callback; 14820Sstevel@tonic-gate 14830Sstevel@tonic-gate break; 14840Sstevel@tonic-gate 14850Sstevel@tonic-gate case TR_EVENT: 14860Sstevel@tonic-gate upper->kbtrans_streams_callback = &trans_event_callback; 14870Sstevel@tonic-gate 14880Sstevel@tonic-gate break; 14890Sstevel@tonic-gate 14900Sstevel@tonic-gate case TR_UNTRANS_EVENT: 14910Sstevel@tonic-gate upper->kbtrans_streams_callback = &untrans_event_callback; 14920Sstevel@tonic-gate 14930Sstevel@tonic-gate break; 14940Sstevel@tonic-gate } 14950Sstevel@tonic-gate } 14960Sstevel@tonic-gate 14970Sstevel@tonic-gate /* 14980Sstevel@tonic-gate * kbtrans_untrans_keypressed_raw: 14990Sstevel@tonic-gate * This is the callback we get if we are in TR_UNTRANS_EVENT and a 15000Sstevel@tonic-gate * key is pressed. This code will just send the scancode up the 15010Sstevel@tonic-gate * stream. 15020Sstevel@tonic-gate */ 15030Sstevel@tonic-gate static void 15040Sstevel@tonic-gate kbtrans_untrans_keypressed_raw(struct kbtrans *upper, kbtrans_key_t key) 15050Sstevel@tonic-gate { 15060Sstevel@tonic-gate Firm_event fe; 15070Sstevel@tonic-gate 15080Sstevel@tonic-gate bzero(&fe, sizeof (fe)); 15090Sstevel@tonic-gate 15100Sstevel@tonic-gate /* 15110Sstevel@tonic-gate * fill in the event 15120Sstevel@tonic-gate */ 15130Sstevel@tonic-gate fe.id = (unsigned short)key; 15140Sstevel@tonic-gate fe.value = 1; 15150Sstevel@tonic-gate 15160Sstevel@tonic-gate /* 15170Sstevel@tonic-gate * Send the event upstream. 15180Sstevel@tonic-gate */ 15190Sstevel@tonic-gate kbtrans_queuepress(upper, key, &fe); 15200Sstevel@tonic-gate } 15210Sstevel@tonic-gate 15220Sstevel@tonic-gate /* 15230Sstevel@tonic-gate * kbtrans_untrans_keyreleased_raw: 15240Sstevel@tonic-gate * This is the callback we get if we are in TR_UNTRANS_EVENT mode 15250Sstevel@tonic-gate * and a key is released. This code will just send the scancode up 15260Sstevel@tonic-gate * the stream. 15270Sstevel@tonic-gate */ 15280Sstevel@tonic-gate static void 15290Sstevel@tonic-gate kbtrans_untrans_keyreleased_raw(struct kbtrans *upper, kbtrans_key_t key) 15300Sstevel@tonic-gate { 15310Sstevel@tonic-gate /* 15320Sstevel@tonic-gate * Deal with a key released event. 15330Sstevel@tonic-gate */ 15340Sstevel@tonic-gate kbtrans_keyreleased(upper, key); 15350Sstevel@tonic-gate } 15360Sstevel@tonic-gate 15370Sstevel@tonic-gate /* 15380Sstevel@tonic-gate * kbtrans_ascii_keypressed: 15390Sstevel@tonic-gate * This is the code if we are in TR_ASCII mode and a key 15400Sstevel@tonic-gate * is pressed. This is where we will do any special processing that 15410Sstevel@tonic-gate * is specific to ASCII key translation. 15420Sstevel@tonic-gate */ 15430Sstevel@tonic-gate /* ARGSUSED */ 15440Sstevel@tonic-gate static void 15450Sstevel@tonic-gate kbtrans_ascii_keypressed( 15460Sstevel@tonic-gate struct kbtrans *upper, 15470Sstevel@tonic-gate uint_t entrytype, 15480Sstevel@tonic-gate kbtrans_key_t key, 15490Sstevel@tonic-gate uint_t entry) 15500Sstevel@tonic-gate { 15510Sstevel@tonic-gate register char *cp; 15520Sstevel@tonic-gate register char *bufp; 15530Sstevel@tonic-gate char buf[14]; 15540Sstevel@tonic-gate struct kbtrans_lower *lower = &upper->kbtrans_lower; 15550Sstevel@tonic-gate 15560Sstevel@tonic-gate /* 15570Sstevel@tonic-gate * Based on the type of key, we may need to do some ASCII 15580Sstevel@tonic-gate * specific post processing. 15590Sstevel@tonic-gate */ 15600Sstevel@tonic-gate switch (entrytype) { 15610Sstevel@tonic-gate 15620Sstevel@tonic-gate case BUCKYBITS: 15630Sstevel@tonic-gate case SHIFTKEYS: 15640Sstevel@tonic-gate case FUNNY: 15650Sstevel@tonic-gate /* 15660Sstevel@tonic-gate * There is no ascii equivalent. We will ignore these 15670Sstevel@tonic-gate * keys 15680Sstevel@tonic-gate */ 15690Sstevel@tonic-gate return; 15700Sstevel@tonic-gate 15710Sstevel@tonic-gate case FUNCKEYS: 15720Sstevel@tonic-gate /* 15730Sstevel@tonic-gate * We need to expand this key to get the ascii 15740Sstevel@tonic-gate * equivalent. These are the function keys (F1, F2 ...) 15750Sstevel@tonic-gate */ 15760Sstevel@tonic-gate bufp = buf; 15770Sstevel@tonic-gate cp = kbtrans_strsetwithdecimal(bufp + 2, 15780Sstevel@tonic-gate (uint_t)((entry & 0x003F) + 192), 15790Sstevel@tonic-gate sizeof (buf) - 5); 15800Sstevel@tonic-gate *bufp++ = '\033'; /* Escape */ 15810Sstevel@tonic-gate *bufp++ = '['; 15820Sstevel@tonic-gate while (*cp != '\0') 15830Sstevel@tonic-gate *bufp++ = *cp++; 15840Sstevel@tonic-gate *bufp++ = 'z'; 15850Sstevel@tonic-gate *bufp = '\0'; 15860Sstevel@tonic-gate 15870Sstevel@tonic-gate /* 15880Sstevel@tonic-gate * Send the result upstream. 15890Sstevel@tonic-gate */ 15900Sstevel@tonic-gate kbtrans_putbuf(buf, upper->kbtrans_streams_readq); 15910Sstevel@tonic-gate 15920Sstevel@tonic-gate return; 15930Sstevel@tonic-gate 15940Sstevel@tonic-gate case STRING: 15950Sstevel@tonic-gate /* 15960Sstevel@tonic-gate * These are the multi byte keys (Home, Up, Down ...) 15970Sstevel@tonic-gate */ 15980Sstevel@tonic-gate cp = &lower->kbtrans_keystringtab[entry & 0x0F][0]; 15990Sstevel@tonic-gate 16000Sstevel@tonic-gate /* 16010Sstevel@tonic-gate * Copy the string from the keystringtable, and send it 16020Sstevel@tonic-gate * upstream a character at a time. 16030Sstevel@tonic-gate */ 16040Sstevel@tonic-gate while (*cp != '\0') { 16050Sstevel@tonic-gate 16060Sstevel@tonic-gate kbtrans_putcode(upper, (uchar_t)*cp); 16070Sstevel@tonic-gate 16080Sstevel@tonic-gate cp++; 16090Sstevel@tonic-gate } 16100Sstevel@tonic-gate 16110Sstevel@tonic-gate return; 16120Sstevel@tonic-gate 16130Sstevel@tonic-gate case PADKEYS: 16140Sstevel@tonic-gate /* 16150Sstevel@tonic-gate * These are the keys on the keypad. Look up the 16160Sstevel@tonic-gate * answer in the kb_numlock_table and send it upstream. 16170Sstevel@tonic-gate */ 16180Sstevel@tonic-gate kbtrans_putcode(upper, 16190Sstevel@tonic-gate lower->kbtrans_numlock_table[entry&0x1F]); 16200Sstevel@tonic-gate 16210Sstevel@tonic-gate return; 16220Sstevel@tonic-gate 16230Sstevel@tonic-gate case 0: /* normal character */ 16240Sstevel@tonic-gate default: 16250Sstevel@tonic-gate break; 16260Sstevel@tonic-gate } 16270Sstevel@tonic-gate 16280Sstevel@tonic-gate /* 16290Sstevel@tonic-gate * Send the byte upstream. 16300Sstevel@tonic-gate */ 16310Sstevel@tonic-gate kbtrans_putcode(upper, entry); 16320Sstevel@tonic-gate 16330Sstevel@tonic-gate } 16340Sstevel@tonic-gate 16350Sstevel@tonic-gate /* 16360Sstevel@tonic-gate * kbtrans_ascii_keyreleased: 16370Sstevel@tonic-gate * This is the function if we are in TR_ASCII mode and a key 16380Sstevel@tonic-gate * is released. ASCII doesn't have the concept of released keys, 16390Sstevel@tonic-gate * or make/break codes. So there is nothing for us to do. 16400Sstevel@tonic-gate */ 16410Sstevel@tonic-gate /* ARGSUSED */ 16420Sstevel@tonic-gate static void 16430Sstevel@tonic-gate kbtrans_ascii_keyreleased(struct kbtrans *upper, kbtrans_key_t key) 16440Sstevel@tonic-gate { 16450Sstevel@tonic-gate /* Nothing to do ... for now */ 16460Sstevel@tonic-gate } 16470Sstevel@tonic-gate 16480Sstevel@tonic-gate /* 16490Sstevel@tonic-gate * kbtrans_ascii_setup_repeat: 16500Sstevel@tonic-gate * This is the function if we are in TR_ASCII mode and the 16510Sstevel@tonic-gate * translation module has decided that a key needs to be repeated. 16520Sstevel@tonic-gate */ 16530Sstevel@tonic-gate /* ARGSUSED */ 16540Sstevel@tonic-gate static void 16550Sstevel@tonic-gate kbtrans_ascii_setup_repeat( 16560Sstevel@tonic-gate struct kbtrans *upper, 16570Sstevel@tonic-gate uint_t entrytype, 16580Sstevel@tonic-gate kbtrans_key_t key) 16590Sstevel@tonic-gate { 16600Sstevel@tonic-gate struct kbtrans_lower *lower = &upper->kbtrans_lower; 16610Sstevel@tonic-gate 16620Sstevel@tonic-gate /* 16630Sstevel@tonic-gate * Cancel any currently repeating keys. This will be a new 16640Sstevel@tonic-gate * key to repeat. 16650Sstevel@tonic-gate */ 16660Sstevel@tonic-gate kbtrans_cancelrpt(upper); 16670Sstevel@tonic-gate 16680Sstevel@tonic-gate /* 16690Sstevel@tonic-gate * Set the value of the key to be repeated. 16700Sstevel@tonic-gate */ 16710Sstevel@tonic-gate lower->kbtrans_repeatkey = key; 16720Sstevel@tonic-gate 16730Sstevel@tonic-gate /* 16740Sstevel@tonic-gate * Start the timeout for repeating this key. kbtrans_rpt will 16750Sstevel@tonic-gate * be called to repeat the key. 16760Sstevel@tonic-gate */ 16770Sstevel@tonic-gate upper->kbtrans_streams_rptid = qtimeout(upper->kbtrans_streams_readq, 16780Sstevel@tonic-gate kbtrans_rpt, (caddr_t)upper, kbtrans_repeat_delay); 16790Sstevel@tonic-gate } 16800Sstevel@tonic-gate 16810Sstevel@tonic-gate /* 16820Sstevel@tonic-gate * kbtrans_trans_event_keypressed: 16830Sstevel@tonic-gate * This is the function if we are in TR_EVENT mode and a key 16840Sstevel@tonic-gate * is pressed. This is where we will do any special processing that 16850Sstevel@tonic-gate * is specific to EVENT key translation. 16860Sstevel@tonic-gate */ 16870Sstevel@tonic-gate static void 16880Sstevel@tonic-gate kbtrans_trans_event_keypressed( 16890Sstevel@tonic-gate struct kbtrans *upper, 16900Sstevel@tonic-gate uint_t entrytype, 16910Sstevel@tonic-gate kbtrans_key_t key, 16920Sstevel@tonic-gate uint_t entry) 16930Sstevel@tonic-gate { 16940Sstevel@tonic-gate Firm_event fe; 16950Sstevel@tonic-gate register char *cp; 16960Sstevel@tonic-gate struct kbtrans_lower *lower = &upper->kbtrans_lower; 16970Sstevel@tonic-gate 16980Sstevel@tonic-gate /* 16990Sstevel@tonic-gate * Based on the type of key, we may need to do some EVENT 17000Sstevel@tonic-gate * specific post processing. 17010Sstevel@tonic-gate */ 17020Sstevel@tonic-gate switch (entrytype) { 17030Sstevel@tonic-gate 17040Sstevel@tonic-gate case SHIFTKEYS: 17050Sstevel@tonic-gate /* 17060Sstevel@tonic-gate * Relying on ordinal correspondence between 17070Sstevel@tonic-gate * vuid_event.h SHIFT_META-SHIFT_TOP & 17080Sstevel@tonic-gate * kbd.h METABIT-SYSTEMBIT in order to 17090Sstevel@tonic-gate * correctly translate entry into fe.id. 17100Sstevel@tonic-gate */ 17110Sstevel@tonic-gate fe.id = SHIFT_CAPSLOCK + (entry & 0x0F); 17120Sstevel@tonic-gate fe.value = 1; 17130Sstevel@tonic-gate kbtrans_keypressed(upper, key, &fe, fe.id); 17140Sstevel@tonic-gate 17150Sstevel@tonic-gate return; 17160Sstevel@tonic-gate 17170Sstevel@tonic-gate case BUCKYBITS: 17180Sstevel@tonic-gate /* 17190Sstevel@tonic-gate * Relying on ordinal correspondence between 17200Sstevel@tonic-gate * vuid_event.h SHIFT_CAPSLOCK-SHIFT_RIGHTCTRL & 17210Sstevel@tonic-gate * kbd.h CAPSLOCK-RIGHTCTRL in order to 17220Sstevel@tonic-gate * correctly translate entry into fe.id. 17230Sstevel@tonic-gate */ 17240Sstevel@tonic-gate fe.id = SHIFT_META + (entry & 0x0F); 17250Sstevel@tonic-gate fe.value = 1; 17260Sstevel@tonic-gate kbtrans_keypressed(upper, key, &fe, fe.id); 17270Sstevel@tonic-gate 17280Sstevel@tonic-gate return; 17290Sstevel@tonic-gate 17300Sstevel@tonic-gate case FUNCKEYS: 17310Sstevel@tonic-gate /* 17320Sstevel@tonic-gate * Take advantage of the similar 17330Sstevel@tonic-gate * ordering of kbd.h function keys and 17340Sstevel@tonic-gate * vuid_event.h function keys to do a 17350Sstevel@tonic-gate * simple translation to achieve a 17360Sstevel@tonic-gate * mapping between the 2 different 17370Sstevel@tonic-gate * address spaces. 17380Sstevel@tonic-gate */ 17390Sstevel@tonic-gate fe.id = KEY_LEFTFIRST + (entry & 0x003F); 17400Sstevel@tonic-gate fe.value = 1; 17410Sstevel@tonic-gate 17420Sstevel@tonic-gate /* 17430Sstevel@tonic-gate * Assume "up" table only generates 17440Sstevel@tonic-gate * shift changes. 17450Sstevel@tonic-gate */ 17460Sstevel@tonic-gate kbtrans_keypressed(upper, key, &fe, fe.id); 17470Sstevel@tonic-gate 17480Sstevel@tonic-gate /* 17490Sstevel@tonic-gate * Function key events can be expanded 17500Sstevel@tonic-gate * by terminal emulator software to 17510Sstevel@tonic-gate * produce the standard escape sequence 17520Sstevel@tonic-gate * generated by the TR_ASCII case above 17530Sstevel@tonic-gate * if a function key event is not used 17540Sstevel@tonic-gate * by terminal emulator software 17550Sstevel@tonic-gate * directly. 17560Sstevel@tonic-gate */ 17570Sstevel@tonic-gate return; 17580Sstevel@tonic-gate 17590Sstevel@tonic-gate case STRING: 17600Sstevel@tonic-gate /* 17610Sstevel@tonic-gate * These are the multi byte keys (Home, Up, Down ...) 17620Sstevel@tonic-gate */ 17630Sstevel@tonic-gate cp = &lower->kbtrans_keystringtab[entry & 0x0F][0]; 17640Sstevel@tonic-gate 17650Sstevel@tonic-gate /* 17660Sstevel@tonic-gate * Copy the string from the keystringtable, and send it 17670Sstevel@tonic-gate * upstream a character at a time. 17680Sstevel@tonic-gate */ 17690Sstevel@tonic-gate while (*cp != '\0') { 17700Sstevel@tonic-gate 17710Sstevel@tonic-gate kbtrans_send_esc_event(*cp, upper); 17720Sstevel@tonic-gate 17730Sstevel@tonic-gate cp++; 17740Sstevel@tonic-gate } 17750Sstevel@tonic-gate 17760Sstevel@tonic-gate return; 17770Sstevel@tonic-gate 17780Sstevel@tonic-gate case PADKEYS: 17790Sstevel@tonic-gate /* 17800Sstevel@tonic-gate * Take advantage of the similar 17810Sstevel@tonic-gate * ordering of kbd.h keypad keys and 17820Sstevel@tonic-gate * vuid_event.h keypad keys to do a 17830Sstevel@tonic-gate * simple translation to achieve a 17840Sstevel@tonic-gate * mapping between the 2 different 17850Sstevel@tonic-gate * address spaces. 17860Sstevel@tonic-gate */ 17870Sstevel@tonic-gate fe.id = VKEY_FIRSTPAD + (entry & 0x001F); 17880Sstevel@tonic-gate fe.value = 1; 17890Sstevel@tonic-gate 17900Sstevel@tonic-gate /* 17910Sstevel@tonic-gate * Assume "up" table only generates 17920Sstevel@tonic-gate * shift changes. 17930Sstevel@tonic-gate */ 17940Sstevel@tonic-gate kbtrans_keypressed(upper, key, &fe, fe.id); 17950Sstevel@tonic-gate 17960Sstevel@tonic-gate /* 17970Sstevel@tonic-gate * Keypad key events can be expanded 17980Sstevel@tonic-gate * by terminal emulator software to 17990Sstevel@tonic-gate * produce the standard ascii character 18000Sstevel@tonic-gate * generated by the TR_ASCII case above 18010Sstevel@tonic-gate * if a keypad key event is not used 18020Sstevel@tonic-gate * by terminal emulator software 18030Sstevel@tonic-gate * directly. 18040Sstevel@tonic-gate */ 18050Sstevel@tonic-gate return; 18060Sstevel@tonic-gate 18070Sstevel@tonic-gate case FUNNY: 18080Sstevel@tonic-gate /* 18090Sstevel@tonic-gate * These are not events. 18100Sstevel@tonic-gate */ 18110Sstevel@tonic-gate switch (entry) { 18120Sstevel@tonic-gate case IDLE: 18130Sstevel@tonic-gate case RESET: 18140Sstevel@tonic-gate case ERROR: 18150Sstevel@tonic-gate /* 18160Sstevel@tonic-gate * Something has happened. Mark all keys as released. 18170Sstevel@tonic-gate */ 18180Sstevel@tonic-gate kbtrans_streams_releaseall(upper); 18190Sstevel@tonic-gate break; 18200Sstevel@tonic-gate } 18210Sstevel@tonic-gate 18220Sstevel@tonic-gate return; 18230Sstevel@tonic-gate 18240Sstevel@tonic-gate case 0: /* normal character */ 18250Sstevel@tonic-gate default: 18260Sstevel@tonic-gate break; 18270Sstevel@tonic-gate } 18280Sstevel@tonic-gate 18290Sstevel@tonic-gate /* 18300Sstevel@tonic-gate * Send the event upstream. 18310Sstevel@tonic-gate */ 18320Sstevel@tonic-gate fe.id = entry; 18330Sstevel@tonic-gate 18340Sstevel@tonic-gate fe.value = 1; 18350Sstevel@tonic-gate 18360Sstevel@tonic-gate kbtrans_queueevent(upper, &fe); 18370Sstevel@tonic-gate } 18380Sstevel@tonic-gate 18390Sstevel@tonic-gate /* 18400Sstevel@tonic-gate * kbtrans_trans_event_keyreleased: 18410Sstevel@tonic-gate * This is the function if we are in TR_EVENT mode and a key 18420Sstevel@tonic-gate * is released. 18430Sstevel@tonic-gate */ 18440Sstevel@tonic-gate /* ARGSUSED */ 18450Sstevel@tonic-gate static void 18460Sstevel@tonic-gate kbtrans_trans_event_keyreleased(struct kbtrans *upper, kbtrans_key_t key) 18470Sstevel@tonic-gate { 18480Sstevel@tonic-gate /* 18490Sstevel@tonic-gate * Mark the key as released and send an event upstream. 18500Sstevel@tonic-gate */ 18510Sstevel@tonic-gate kbtrans_keyreleased(upper, key); 18520Sstevel@tonic-gate } 18530Sstevel@tonic-gate 18540Sstevel@tonic-gate /* 18550Sstevel@tonic-gate * kbtrans_trans_event_setup_repeat: 18560Sstevel@tonic-gate * This is the function if we are in TR_EVENT mode and the 18570Sstevel@tonic-gate * translation module has decided that a key needs to be repeated. 18580Sstevel@tonic-gate * We will set a timeout to retranslate the repeat key. 18590Sstevel@tonic-gate */ 18600Sstevel@tonic-gate static void 18610Sstevel@tonic-gate kbtrans_trans_event_setup_repeat( 18620Sstevel@tonic-gate struct kbtrans *upper, 18630Sstevel@tonic-gate uint_t entrytype, 18640Sstevel@tonic-gate kbtrans_key_t key) 18650Sstevel@tonic-gate { 18660Sstevel@tonic-gate struct kbtrans_lower *lower = &upper->kbtrans_lower; 18670Sstevel@tonic-gate 18680Sstevel@tonic-gate /* 18690Sstevel@tonic-gate * Function keys and keypad keys do not repeat when we are in 18700Sstevel@tonic-gate * EVENT mode. 18710Sstevel@tonic-gate */ 18720Sstevel@tonic-gate if (entrytype == FUNCKEYS || entrytype == PADKEYS) { 18730Sstevel@tonic-gate 18740Sstevel@tonic-gate return; 18750Sstevel@tonic-gate } 18760Sstevel@tonic-gate 18770Sstevel@tonic-gate /* 18780Sstevel@tonic-gate * Cancel any currently repeating keys. This will be a new 18790Sstevel@tonic-gate * key to repeat. 18800Sstevel@tonic-gate */ 18810Sstevel@tonic-gate kbtrans_cancelrpt(upper); 18820Sstevel@tonic-gate 18830Sstevel@tonic-gate /* 18840Sstevel@tonic-gate * Set the value of the key to be repeated. 18850Sstevel@tonic-gate */ 18860Sstevel@tonic-gate lower->kbtrans_repeatkey = key; 18870Sstevel@tonic-gate 18880Sstevel@tonic-gate /* 18890Sstevel@tonic-gate * Start the timeout for repeating this key. kbtrans_rpt will 18900Sstevel@tonic-gate * be called to repeat the key. 18910Sstevel@tonic-gate */ 18920Sstevel@tonic-gate upper->kbtrans_streams_rptid = qtimeout(upper->kbtrans_streams_readq, 18930Sstevel@tonic-gate kbtrans_rpt, (caddr_t)upper, kbtrans_repeat_delay); 18940Sstevel@tonic-gate } 18950Sstevel@tonic-gate 18960Sstevel@tonic-gate /* 18970Sstevel@tonic-gate * Administer the key tables. 18980Sstevel@tonic-gate */ 18990Sstevel@tonic-gate 19000Sstevel@tonic-gate /* 19010Sstevel@tonic-gate * Old special codes. 19020Sstevel@tonic-gate */ 19030Sstevel@tonic-gate #define OLD_SHIFTKEYS 0x80 19040Sstevel@tonic-gate #define OLD_BUCKYBITS 0x90 19050Sstevel@tonic-gate #define OLD_FUNNY 0xA0 19060Sstevel@tonic-gate #define OLD_FA_UMLAUT 0xA9 19070Sstevel@tonic-gate #define OLD_FA_CFLEX 0xAA 19080Sstevel@tonic-gate #define OLD_FA_TILDE 0xAB 19090Sstevel@tonic-gate #define OLD_FA_CEDILLA 0xAC 19100Sstevel@tonic-gate #define OLD_FA_ACUTE 0xAD 19110Sstevel@tonic-gate #define OLD_FA_GRAVE 0xAE 19120Sstevel@tonic-gate #define OLD_ISOCHAR 0xAF 19130Sstevel@tonic-gate #define OLD_STRING 0xB0 19140Sstevel@tonic-gate #define OLD_LEFTFUNC 0xC0 19150Sstevel@tonic-gate #define OLD_RIGHTFUNC 0xD0 19160Sstevel@tonic-gate #define OLD_TOPFUNC 0xE0 19170Sstevel@tonic-gate #define OLD_BOTTOMFUNC 0xF0 19180Sstevel@tonic-gate 19190Sstevel@tonic-gate /* 19200Sstevel@tonic-gate * Map old special codes to new ones. 19210Sstevel@tonic-gate * Indexed by ((old special code) >> 4) & 0x07; add (old special code) & 0x0F. 19220Sstevel@tonic-gate */ 19230Sstevel@tonic-gate static ushort_t special_old_to_new[] = { 19240Sstevel@tonic-gate SHIFTKEYS, 19250Sstevel@tonic-gate BUCKYBITS, 19260Sstevel@tonic-gate FUNNY, 19270Sstevel@tonic-gate STRING, 19280Sstevel@tonic-gate LEFTFUNC, 19290Sstevel@tonic-gate RIGHTFUNC, 19300Sstevel@tonic-gate TOPFUNC, 19310Sstevel@tonic-gate BOTTOMFUNC, 19320Sstevel@tonic-gate }; 19330Sstevel@tonic-gate 19340Sstevel@tonic-gate 19350Sstevel@tonic-gate /* 19360Sstevel@tonic-gate * kbtrans_setkey: 19370Sstevel@tonic-gate * Set individual keystation translation from old-style entry. 19380Sstevel@tonic-gate */ 19390Sstevel@tonic-gate static int 19400Sstevel@tonic-gate kbtrans_setkey(struct kbtrans_lower *lower, struct kiockey *key, cred_t *cr) 19410Sstevel@tonic-gate { 19420Sstevel@tonic-gate int strtabindex, i; 19430Sstevel@tonic-gate unsigned short *ke; 19440Sstevel@tonic-gate register int tablemask; 19450Sstevel@tonic-gate register ushort_t entry; 19460Sstevel@tonic-gate register struct keyboard *kp; 19470Sstevel@tonic-gate 19480Sstevel@tonic-gate kp = lower->kbtrans_keyboard; 19490Sstevel@tonic-gate 19500Sstevel@tonic-gate if (key->kio_station >= kp->k_keymap_size) 19510Sstevel@tonic-gate 19520Sstevel@tonic-gate return (EINVAL); 19530Sstevel@tonic-gate 19540Sstevel@tonic-gate if (lower->kbtrans_keyboard == NULL) 19550Sstevel@tonic-gate 19560Sstevel@tonic-gate return (EINVAL); 19570Sstevel@tonic-gate 19580Sstevel@tonic-gate tablemask = key->kio_tablemask; 19590Sstevel@tonic-gate 19600Sstevel@tonic-gate switch (tablemask) { 19610Sstevel@tonic-gate case KIOCABORT1: 19620Sstevel@tonic-gate case KIOCABORT1A: 19630Sstevel@tonic-gate case KIOCABORT2: 19640Sstevel@tonic-gate i = secpolicy_console(cr); 19650Sstevel@tonic-gate if (i != 0) 19660Sstevel@tonic-gate return (i); 19670Sstevel@tonic-gate 19680Sstevel@tonic-gate switch (tablemask) { 19690Sstevel@tonic-gate case KIOCABORT1: 19700Sstevel@tonic-gate kp->k_abort1 = key->kio_station; 19710Sstevel@tonic-gate break; 19720Sstevel@tonic-gate case KIOCABORT1A: 19730Sstevel@tonic-gate kp->k_abort1a = key->kio_station; 19740Sstevel@tonic-gate break; 19750Sstevel@tonic-gate case KIOCABORT2: 19760Sstevel@tonic-gate kp->k_abort2 = key->kio_station; 19770Sstevel@tonic-gate break; 19780Sstevel@tonic-gate } 19790Sstevel@tonic-gate return (0); 19800Sstevel@tonic-gate } 19810Sstevel@tonic-gate 19820Sstevel@tonic-gate if (tablemask & ALTGRAPHMASK) 19830Sstevel@tonic-gate return (EINVAL); 19840Sstevel@tonic-gate 19850Sstevel@tonic-gate ke = kbtrans_find_entry(lower, (uint_t)tablemask, key->kio_station); 19860Sstevel@tonic-gate if (ke == NULL) 19870Sstevel@tonic-gate return (EINVAL); 19880Sstevel@tonic-gate 19890Sstevel@tonic-gate if (key->kio_entry >= (uchar_t)OLD_STRING && 19900Sstevel@tonic-gate key->kio_entry <= (uchar_t)(OLD_STRING + 15)) { 19910Sstevel@tonic-gate strtabindex = key->kio_entry - OLD_STRING; 19920Sstevel@tonic-gate bcopy(key->kio_string, 19930Sstevel@tonic-gate lower->kbtrans_keystringtab[strtabindex], KTAB_STRLEN); 19940Sstevel@tonic-gate lower->kbtrans_keystringtab[strtabindex][KTAB_STRLEN-1] = '\0'; 19950Sstevel@tonic-gate } 19960Sstevel@tonic-gate 19970Sstevel@tonic-gate entry = key->kio_entry; 19980Sstevel@tonic-gate 19990Sstevel@tonic-gate /* 20000Sstevel@tonic-gate * There's nothing we need do with OLD_ISOCHAR. 20010Sstevel@tonic-gate */ 20020Sstevel@tonic-gate if (entry != OLD_ISOCHAR) { 20030Sstevel@tonic-gate if (entry & 0x80) { 20040Sstevel@tonic-gate if (entry >= OLD_FA_UMLAUT && entry <= OLD_FA_GRAVE) 20050Sstevel@tonic-gate entry = FA_CLASS + (entry & 0x0F) - 9; 20060Sstevel@tonic-gate else 20070Sstevel@tonic-gate entry = 20080Sstevel@tonic-gate special_old_to_new[entry >> 4 & 0x07] 20090Sstevel@tonic-gate + (entry & 0x0F); 20100Sstevel@tonic-gate } 20110Sstevel@tonic-gate } 20120Sstevel@tonic-gate 20130Sstevel@tonic-gate *ke = entry; 20140Sstevel@tonic-gate 20150Sstevel@tonic-gate return (0); 20160Sstevel@tonic-gate } 20170Sstevel@tonic-gate 20180Sstevel@tonic-gate 20190Sstevel@tonic-gate /* 20200Sstevel@tonic-gate * Map new special codes to old ones. 20210Sstevel@tonic-gate * Indexed by (new special code) >> 8; add (new special code) & 0xFF. 20220Sstevel@tonic-gate */ 20230Sstevel@tonic-gate static uchar_t special_new_to_old[] = { 20240Sstevel@tonic-gate 0, /* normal */ 20250Sstevel@tonic-gate OLD_SHIFTKEYS, /* SHIFTKEYS */ 20260Sstevel@tonic-gate OLD_BUCKYBITS, /* BUCKYBITS */ 20270Sstevel@tonic-gate OLD_FUNNY, /* FUNNY */ 20280Sstevel@tonic-gate OLD_FA_UMLAUT, /* FA_CLASS */ 20290Sstevel@tonic-gate OLD_STRING, /* STRING */ 20300Sstevel@tonic-gate OLD_LEFTFUNC, /* FUNCKEYS */ 20310Sstevel@tonic-gate }; 20320Sstevel@tonic-gate 20330Sstevel@tonic-gate 20340Sstevel@tonic-gate /* 20350Sstevel@tonic-gate * kbtrans_getkey: 20360Sstevel@tonic-gate * Get individual keystation translation as old-style entry. 20370Sstevel@tonic-gate */ 20380Sstevel@tonic-gate static int 20390Sstevel@tonic-gate kbtrans_getkey(struct kbtrans_lower *lower, struct kiockey *key) 20400Sstevel@tonic-gate { 20410Sstevel@tonic-gate int strtabindex; 20420Sstevel@tonic-gate unsigned short *ke; 20430Sstevel@tonic-gate register ushort_t entry; 20440Sstevel@tonic-gate struct keyboard *kp; 20450Sstevel@tonic-gate 20460Sstevel@tonic-gate kp = lower->kbtrans_keyboard; 20470Sstevel@tonic-gate 20480Sstevel@tonic-gate if (key->kio_station >= kp->k_keymap_size) 20490Sstevel@tonic-gate return (EINVAL); 20500Sstevel@tonic-gate 20510Sstevel@tonic-gate if (lower->kbtrans_keyboard == NULL) 20520Sstevel@tonic-gate return (EINVAL); 20530Sstevel@tonic-gate 20540Sstevel@tonic-gate switch (key->kio_tablemask) { 20550Sstevel@tonic-gate case KIOCABORT1: 20560Sstevel@tonic-gate key->kio_station = kp->k_abort1; 20570Sstevel@tonic-gate return (0); 20580Sstevel@tonic-gate case KIOCABORT1A: 20590Sstevel@tonic-gate key->kio_station = kp->k_abort1a; 20600Sstevel@tonic-gate return (0); 20610Sstevel@tonic-gate case KIOCABORT2: 20620Sstevel@tonic-gate key->kio_station = kp->k_abort2; 20630Sstevel@tonic-gate return (0); 20640Sstevel@tonic-gate } 20650Sstevel@tonic-gate 20660Sstevel@tonic-gate ke = kbtrans_find_entry(lower, (uint_t)key->kio_tablemask, 20670Sstevel@tonic-gate key->kio_station); 20680Sstevel@tonic-gate if (ke == NULL) 20690Sstevel@tonic-gate return (EINVAL); 20700Sstevel@tonic-gate 20710Sstevel@tonic-gate entry = *ke; 20720Sstevel@tonic-gate 20730Sstevel@tonic-gate if (entry & 0xFF00) 20740Sstevel@tonic-gate key->kio_entry = 20750Sstevel@tonic-gate special_new_to_old[(ushort_t)(entry & 0xFF00) >> 8] 20760Sstevel@tonic-gate + (entry & 0x00FF); 20770Sstevel@tonic-gate else { 20780Sstevel@tonic-gate if (entry & 0x80) 20790Sstevel@tonic-gate key->kio_entry = (ushort_t)OLD_ISOCHAR; /* you lose */ 20800Sstevel@tonic-gate else 20810Sstevel@tonic-gate key->kio_entry = (ushort_t)entry; 20820Sstevel@tonic-gate } 20830Sstevel@tonic-gate 20840Sstevel@tonic-gate if (entry >= STRING && entry <= (uchar_t)(STRING + 15)) { 20850Sstevel@tonic-gate strtabindex = entry - STRING; 20860Sstevel@tonic-gate bcopy(lower->kbtrans_keystringtab[strtabindex], 20870Sstevel@tonic-gate key->kio_string, KTAB_STRLEN); 20880Sstevel@tonic-gate } 20890Sstevel@tonic-gate return (0); 20900Sstevel@tonic-gate } 20910Sstevel@tonic-gate 20920Sstevel@tonic-gate 20930Sstevel@tonic-gate /* 20940Sstevel@tonic-gate * kbtrans_skey: 20950Sstevel@tonic-gate * Set individual keystation translation from new-style entry. 20960Sstevel@tonic-gate */ 20970Sstevel@tonic-gate static int 20980Sstevel@tonic-gate kbtrans_skey(struct kbtrans_lower *lower, struct kiockeymap *key, cred_t *cr) 20990Sstevel@tonic-gate { 21000Sstevel@tonic-gate int strtabindex, i; 21010Sstevel@tonic-gate unsigned short *ke; 21020Sstevel@tonic-gate struct keyboard *kp; 21030Sstevel@tonic-gate 21040Sstevel@tonic-gate kp = lower->kbtrans_keyboard; 21050Sstevel@tonic-gate 21060Sstevel@tonic-gate if (key->kio_station >= kp->k_keymap_size) { 21070Sstevel@tonic-gate return (EINVAL); 21080Sstevel@tonic-gate 21090Sstevel@tonic-gate } 21100Sstevel@tonic-gate 21110Sstevel@tonic-gate if (lower->kbtrans_keyboard == NULL) { 21120Sstevel@tonic-gate return (EINVAL); 21130Sstevel@tonic-gate } 21140Sstevel@tonic-gate 21150Sstevel@tonic-gate switch (key->kio_tablemask) { 21160Sstevel@tonic-gate case KIOCABORT1: 21170Sstevel@tonic-gate case KIOCABORT1A: 21180Sstevel@tonic-gate case KIOCABORT2: 21190Sstevel@tonic-gate i = secpolicy_console(cr); 21200Sstevel@tonic-gate if (i != 0) 21210Sstevel@tonic-gate return (i); 21220Sstevel@tonic-gate switch (key->kio_tablemask) { 21230Sstevel@tonic-gate case KIOCABORT1: 21240Sstevel@tonic-gate kp->k_abort1 = key->kio_station; 21250Sstevel@tonic-gate break; 21260Sstevel@tonic-gate case KIOCABORT1A: 21270Sstevel@tonic-gate kp->k_abort1a = key->kio_station; 21280Sstevel@tonic-gate break; 21290Sstevel@tonic-gate case KIOCABORT2: 21300Sstevel@tonic-gate kp->k_abort2 = key->kio_station; 21310Sstevel@tonic-gate break; 21320Sstevel@tonic-gate } 21330Sstevel@tonic-gate return (0); 21340Sstevel@tonic-gate } 21350Sstevel@tonic-gate 21360Sstevel@tonic-gate ke = kbtrans_find_entry(lower, (uint_t)key->kio_tablemask, 21370Sstevel@tonic-gate key->kio_station); 21380Sstevel@tonic-gate if (ke == NULL) 21390Sstevel@tonic-gate return (EINVAL); 21400Sstevel@tonic-gate 21410Sstevel@tonic-gate if (key->kio_entry >= STRING && 21420Sstevel@tonic-gate key->kio_entry <= (ushort_t)(STRING + 15)) { 21430Sstevel@tonic-gate strtabindex = key->kio_entry-STRING; 21440Sstevel@tonic-gate bcopy(key->kio_string, 21450Sstevel@tonic-gate lower->kbtrans_keystringtab[strtabindex], KTAB_STRLEN); 21460Sstevel@tonic-gate lower->kbtrans_keystringtab[strtabindex][KTAB_STRLEN-1] = '\0'; 21470Sstevel@tonic-gate } 21480Sstevel@tonic-gate 21490Sstevel@tonic-gate *ke = key->kio_entry; 21500Sstevel@tonic-gate 21510Sstevel@tonic-gate return (0); 21520Sstevel@tonic-gate } 21530Sstevel@tonic-gate 21540Sstevel@tonic-gate 21550Sstevel@tonic-gate /* 21560Sstevel@tonic-gate * kbtrans_gkey: 21570Sstevel@tonic-gate * Get individual keystation translation as new-style entry. 21580Sstevel@tonic-gate */ 21590Sstevel@tonic-gate static int 21600Sstevel@tonic-gate kbtrans_gkey(struct kbtrans_lower *lower, struct kiockeymap *key) 21610Sstevel@tonic-gate { 21620Sstevel@tonic-gate int strtabindex; 21630Sstevel@tonic-gate unsigned short *ke; 21640Sstevel@tonic-gate struct keyboard *kp; 21650Sstevel@tonic-gate 21660Sstevel@tonic-gate kp = lower->kbtrans_keyboard; 21670Sstevel@tonic-gate 21680Sstevel@tonic-gate if (key->kio_station >= kp->k_keymap_size) 21690Sstevel@tonic-gate return (EINVAL); 21700Sstevel@tonic-gate 21710Sstevel@tonic-gate if (lower->kbtrans_keyboard == NULL) 21720Sstevel@tonic-gate return (EINVAL); 21730Sstevel@tonic-gate 21740Sstevel@tonic-gate switch (key->kio_tablemask) { 21750Sstevel@tonic-gate case KIOCABORT1: 21760Sstevel@tonic-gate key->kio_station = kp->k_abort1; 21770Sstevel@tonic-gate return (0); 21780Sstevel@tonic-gate case KIOCABORT1A: 21790Sstevel@tonic-gate key->kio_station = kp->k_abort1a; 21800Sstevel@tonic-gate return (0); 21810Sstevel@tonic-gate case KIOCABORT2: 21820Sstevel@tonic-gate key->kio_station = kp->k_abort2; 21830Sstevel@tonic-gate return (0); 21840Sstevel@tonic-gate } 21850Sstevel@tonic-gate 21860Sstevel@tonic-gate ke = kbtrans_find_entry(lower, (uint_t)key->kio_tablemask, 21870Sstevel@tonic-gate key->kio_station); 21880Sstevel@tonic-gate if (ke == NULL) 21890Sstevel@tonic-gate return (EINVAL); 21900Sstevel@tonic-gate 21910Sstevel@tonic-gate key->kio_entry = *ke; 21920Sstevel@tonic-gate 21930Sstevel@tonic-gate if (key->kio_entry >= STRING && 21940Sstevel@tonic-gate key->kio_entry <= (ushort_t)(STRING + 15)) { 21950Sstevel@tonic-gate strtabindex = key->kio_entry-STRING; 21960Sstevel@tonic-gate bcopy(lower->kbtrans_keystringtab[strtabindex], 21970Sstevel@tonic-gate key->kio_string, KTAB_STRLEN); 21980Sstevel@tonic-gate } 21990Sstevel@tonic-gate return (0); 22000Sstevel@tonic-gate } 2201