1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*0Sstevel@tonic-gate * Use is subject to license terms.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate /*
30*0Sstevel@tonic-gate * Generic keyboard support: translation
31*0Sstevel@tonic-gate *
32*0Sstevel@tonic-gate * This module is project private. Please see PSARC/1998/176 and
33*0Sstevel@tonic-gate * PSARC/1998/026 for references to the kbtrans module.
34*0Sstevel@tonic-gate *
35*0Sstevel@tonic-gate * It is believed that it is safe to call these functions within debugger mode
36*0Sstevel@tonic-gate * except kbtrans_dprintf. Debugger mode is a single threaded mode where most
37*0Sstevel@tonic-gate * kernel services are not available, including memory allocation. Debugger
38*0Sstevel@tonic-gate * mode is for kmdb and OBP debugging, where the debugger calls back into the
39*0Sstevel@tonic-gate * kernel to obtain console input.
40*0Sstevel@tonic-gate *
41*0Sstevel@tonic-gate * Please be _very_ careful about what external functions you call.
42*0Sstevel@tonic-gate */
43*0Sstevel@tonic-gate
44*0Sstevel@tonic-gate #define KEYMAP_SIZE_VARIABLE
45*0Sstevel@tonic-gate
46*0Sstevel@tonic-gate #include <sys/types.h>
47*0Sstevel@tonic-gate #include <sys/cred.h>
48*0Sstevel@tonic-gate #include <sys/ddi.h>
49*0Sstevel@tonic-gate #include <sys/sunddi.h>
50*0Sstevel@tonic-gate #include <sys/kmem.h>
51*0Sstevel@tonic-gate #include <sys/kbd.h>
52*0Sstevel@tonic-gate #include <sys/cmn_err.h>
53*0Sstevel@tonic-gate #include <sys/modctl.h>
54*0Sstevel@tonic-gate #include <sys/kbio.h>
55*0Sstevel@tonic-gate #include <sys/vuid_event.h>
56*0Sstevel@tonic-gate #include <sys/consdev.h>
57*0Sstevel@tonic-gate #include <sys/kbtrans.h>
58*0Sstevel@tonic-gate #include <sys/errno.h>
59*0Sstevel@tonic-gate #include <sys/promif.h>
60*0Sstevel@tonic-gate #include <sys/varargs.h>
61*0Sstevel@tonic-gate #include "kbtrans_lower.h"
62*0Sstevel@tonic-gate
63*0Sstevel@tonic-gate /*
64*0Sstevel@tonic-gate * Internal Function Prototypes
65*0Sstevel@tonic-gate */
66*0Sstevel@tonic-gate static boolean_t kbtrans_do_compose(struct kbtrans_lower *, ushort_t,
67*0Sstevel@tonic-gate ushort_t, ushort_t *);
68*0Sstevel@tonic-gate static void kbtrans_translate(struct kbtrans_lower *,
69*0Sstevel@tonic-gate struct keyboard_callback *, kbtrans_key_t,
70*0Sstevel@tonic-gate enum keystate);
71*0Sstevel@tonic-gate /*
72*0Sstevel@tonic-gate * kbtrans_processkey:
73*0Sstevel@tonic-gate *
74*0Sstevel@tonic-gate * lower - state information used by the calling driver
75*0Sstevel@tonic-gate * this parameter is passed back to the callback routines.
76*0Sstevel@tonic-gate * key - scancode
77*0Sstevel@tonic-gate * state - KEY_PRESSED / KEY_RELEASED
78*0Sstevel@tonic-gate *
79*0Sstevel@tonic-gate * This routine checks to see if there is a raw callback, and calls it
80*0Sstevel@tonic-gate * if it exists. If there is no raw callback, the key is translated.
81*0Sstevel@tonic-gate * The raw callback allows the driver that called the translation module
82*0Sstevel@tonic-gate * to be passed untranslated scancodes.
83*0Sstevel@tonic-gate */
84*0Sstevel@tonic-gate void
kbtrans_processkey(struct kbtrans_lower * lower,struct keyboard_callback * cb,kbtrans_key_t key,enum keystate state)85*0Sstevel@tonic-gate kbtrans_processkey(struct kbtrans_lower *lower,
86*0Sstevel@tonic-gate struct keyboard_callback *cb,
87*0Sstevel@tonic-gate kbtrans_key_t key,
88*0Sstevel@tonic-gate enum keystate state)
89*0Sstevel@tonic-gate {
90*0Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (lower, "kbtrans_processkey: "
91*0Sstevel@tonic-gate "newstate=%d key=%d", state, key));
92*0Sstevel@tonic-gate
93*0Sstevel@tonic-gate /*
94*0Sstevel@tonic-gate * If there is a raw routine, then call it and return.
95*0Sstevel@tonic-gate */
96*0Sstevel@tonic-gate if (cb->kc_keypressed_raw != NULL) {
97*0Sstevel@tonic-gate
98*0Sstevel@tonic-gate if (state == KEY_PRESSED) {
99*0Sstevel@tonic-gate
100*0Sstevel@tonic-gate cb->kc_keypressed_raw(lower->kbtrans_upper, key);
101*0Sstevel@tonic-gate } else {
102*0Sstevel@tonic-gate
103*0Sstevel@tonic-gate cb->kc_keyreleased_raw(lower->kbtrans_upper, key);
104*0Sstevel@tonic-gate }
105*0Sstevel@tonic-gate
106*0Sstevel@tonic-gate return;
107*0Sstevel@tonic-gate }
108*0Sstevel@tonic-gate
109*0Sstevel@tonic-gate /*
110*0Sstevel@tonic-gate * translate the scancode into a key.
111*0Sstevel@tonic-gate */
112*0Sstevel@tonic-gate kbtrans_translate(lower, cb, key, state);
113*0Sstevel@tonic-gate }
114*0Sstevel@tonic-gate
115*0Sstevel@tonic-gate
116*0Sstevel@tonic-gate /*
117*0Sstevel@tonic-gate * kbtrans_translate:
118*0Sstevel@tonic-gate *
119*0Sstevel@tonic-gate * lower - state information used by the calling driver
120*0Sstevel@tonic-gate * this parameter is passed back to the callback routines.
121*0Sstevel@tonic-gate * key - scan code
122*0Sstevel@tonic-gate * state - KEY_PRESSED / KEY_RELEASED
123*0Sstevel@tonic-gate *
124*0Sstevel@tonic-gate * Called to process key events if we are in TR_ASCII or TR_EVENT
125*0Sstevel@tonic-gate * (sunview) mode. This routine will call the appropriate translation_callback
126*0Sstevel@tonic-gate * for the character when it is done translating it.
127*0Sstevel@tonic-gate */
128*0Sstevel@tonic-gate static void
kbtrans_translate(struct kbtrans_lower * lower,struct keyboard_callback * cb,kbtrans_key_t key,enum keystate newstate)129*0Sstevel@tonic-gate kbtrans_translate(struct kbtrans_lower *lower,
130*0Sstevel@tonic-gate struct keyboard_callback *cb,
131*0Sstevel@tonic-gate kbtrans_key_t key,
132*0Sstevel@tonic-gate enum keystate newstate)
133*0Sstevel@tonic-gate {
134*0Sstevel@tonic-gate unsigned shiftmask;
135*0Sstevel@tonic-gate register ushort_t entry;
136*0Sstevel@tonic-gate register ushort_t entrytype;
137*0Sstevel@tonic-gate ushort_t result_iso;
138*0Sstevel@tonic-gate unsigned short *ke;
139*0Sstevel@tonic-gate int i;
140*0Sstevel@tonic-gate boolean_t good_compose;
141*0Sstevel@tonic-gate
142*0Sstevel@tonic-gate DPRINTF(PRINT_L0, PRINT_MASK_ALL, (lower, "KEY TRANSLATE "
143*0Sstevel@tonic-gate "newstate=0x%x key=0x%x\n", newstate, key));
144*0Sstevel@tonic-gate
145*0Sstevel@tonic-gate if (lower->kbtrans_keyboard == NULL) {
146*0Sstevel@tonic-gate /*
147*0Sstevel@tonic-gate * Nobody has told us about this keyboard yet.
148*0Sstevel@tonic-gate */
149*0Sstevel@tonic-gate return;
150*0Sstevel@tonic-gate }
151*0Sstevel@tonic-gate
152*0Sstevel@tonic-gate /*
153*0Sstevel@tonic-gate * Get the current state of the shiftmask
154*0Sstevel@tonic-gate */
155*0Sstevel@tonic-gate shiftmask = lower->kbtrans_shiftmask;
156*0Sstevel@tonic-gate
157*0Sstevel@tonic-gate /*
158*0Sstevel@tonic-gate * If the key has been released, then or in the UPMASK flag.
159*0Sstevel@tonic-gate */
160*0Sstevel@tonic-gate if (newstate == KEY_RELEASED)
161*0Sstevel@tonic-gate shiftmask |= UPMASK;
162*0Sstevel@tonic-gate
163*0Sstevel@tonic-gate /*
164*0Sstevel@tonic-gate * Based on the shiftmask, lookup the keymap entry that we should
165*0Sstevel@tonic-gate * be using for this scancode.
166*0Sstevel@tonic-gate */
167*0Sstevel@tonic-gate ke = kbtrans_find_entry(lower, shiftmask, key);
168*0Sstevel@tonic-gate
169*0Sstevel@tonic-gate if (ke == NULL) {
170*0Sstevel@tonic-gate /*
171*0Sstevel@tonic-gate * This is a gross error. Cancel the repeat key and exit,
172*0Sstevel@tonic-gate * we can not translate this scancode.
173*0Sstevel@tonic-gate */
174*0Sstevel@tonic-gate cb->kc_cancel_repeat(lower->kbtrans_upper);
175*0Sstevel@tonic-gate
176*0Sstevel@tonic-gate return;
177*0Sstevel@tonic-gate }
178*0Sstevel@tonic-gate
179*0Sstevel@tonic-gate /*
180*0Sstevel@tonic-gate * Get the key for this scancode.
181*0Sstevel@tonic-gate */
182*0Sstevel@tonic-gate entry = *ke;
183*0Sstevel@tonic-gate
184*0Sstevel@tonic-gate if (entry == NONL) {
185*0Sstevel@tonic-gate /*
186*0Sstevel@tonic-gate * NONL appears only in the Num Lock table, and indicates that
187*0Sstevel@tonic-gate * this key is not affected by Num Lock. This means we should
188*0Sstevel@tonic-gate * ask for the table we would have gotten had Num Lock not been
189*0Sstevel@tonic-gate * down, and translate using that table.
190*0Sstevel@tonic-gate */
191*0Sstevel@tonic-gate ke = kbtrans_find_entry(lower, shiftmask & ~NUMLOCKMASK,
192*0Sstevel@tonic-gate key);
193*0Sstevel@tonic-gate
194*0Sstevel@tonic-gate if (ke == NULL) {
195*0Sstevel@tonic-gate /*
196*0Sstevel@tonic-gate * This is a gross error. Cancel the repeat key and
197*0Sstevel@tonic-gate * exit, we can not translate this scancode.
198*0Sstevel@tonic-gate */
199*0Sstevel@tonic-gate cb->kc_cancel_repeat(lower->kbtrans_upper);
200*0Sstevel@tonic-gate
201*0Sstevel@tonic-gate return;
202*0Sstevel@tonic-gate }
203*0Sstevel@tonic-gate
204*0Sstevel@tonic-gate /*
205*0Sstevel@tonic-gate * Get the new key for this scancode.
206*0Sstevel@tonic-gate */
207*0Sstevel@tonic-gate entry = *ke;
208*0Sstevel@tonic-gate }
209*0Sstevel@tonic-gate
210*0Sstevel@tonic-gate /*
211*0Sstevel@tonic-gate * The entrytype indicates what category of key we are processing.
212*0Sstevel@tonic-gate * Categories include shift keys, function keys, and numeric keypad
213*0Sstevel@tonic-gate * keys.
214*0Sstevel@tonic-gate */
215*0Sstevel@tonic-gate entrytype = (ushort_t)(entry & 0xFF00);
216*0Sstevel@tonic-gate
217*0Sstevel@tonic-gate if (entrytype == SHIFTKEYS) {
218*0Sstevel@tonic-gate /*
219*0Sstevel@tonic-gate * Handle the state of toggle shifts specially.
220*0Sstevel@tonic-gate * Ups should be ignored, and downs should be mapped to ups if
221*0Sstevel@tonic-gate * that shift is currently on.
222*0Sstevel@tonic-gate */
223*0Sstevel@tonic-gate if ((1 << (entry & 0x0F)) &
224*0Sstevel@tonic-gate lower->kbtrans_keyboard->k_toggleshifts) {
225*0Sstevel@tonic-gate if ((1 << (entry & 0x0F)) &
226*0Sstevel@tonic-gate lower->kbtrans_togglemask) {
227*0Sstevel@tonic-gate newstate = KEY_RELEASED; /* toggling off */
228*0Sstevel@tonic-gate } else {
229*0Sstevel@tonic-gate newstate = KEY_PRESSED; /* toggling on */
230*0Sstevel@tonic-gate }
231*0Sstevel@tonic-gate }
232*0Sstevel@tonic-gate } else {
233*0Sstevel@tonic-gate /*
234*0Sstevel@tonic-gate * Handle Compose and floating accent key sequences
235*0Sstevel@tonic-gate */
236*0Sstevel@tonic-gate switch (lower->kbtrans_state) {
237*0Sstevel@tonic-gate case COMPOSE1:
238*0Sstevel@tonic-gate if (newstate == KEY_RELEASED)
239*0Sstevel@tonic-gate
240*0Sstevel@tonic-gate return;
241*0Sstevel@tonic-gate
242*0Sstevel@tonic-gate if (entry < ASCII_SET_SIZE) {
243*0Sstevel@tonic-gate if (lower->kbtrans_compose_map[entry] >= 0) {
244*0Sstevel@tonic-gate lower->kbtrans_compose_key = entry;
245*0Sstevel@tonic-gate lower->kbtrans_state = COMPOSE2;
246*0Sstevel@tonic-gate
247*0Sstevel@tonic-gate return;
248*0Sstevel@tonic-gate }
249*0Sstevel@tonic-gate }
250*0Sstevel@tonic-gate lower->kbtrans_state = NORMAL;
251*0Sstevel@tonic-gate lower->kbtrans_led_state &= ~LED_COMPOSE;
252*0Sstevel@tonic-gate
253*0Sstevel@tonic-gate cb->kc_setled(lower->kbtrans_upper);
254*0Sstevel@tonic-gate
255*0Sstevel@tonic-gate return;
256*0Sstevel@tonic-gate
257*0Sstevel@tonic-gate case COMPOSE2:
258*0Sstevel@tonic-gate if (newstate == KEY_RELEASED)
259*0Sstevel@tonic-gate return;
260*0Sstevel@tonic-gate
261*0Sstevel@tonic-gate /* next state is "normal" */
262*0Sstevel@tonic-gate lower->kbtrans_state = NORMAL;
263*0Sstevel@tonic-gate lower->kbtrans_led_state &= ~LED_COMPOSE;
264*0Sstevel@tonic-gate
265*0Sstevel@tonic-gate cb->kc_setled(lower->kbtrans_upper);
266*0Sstevel@tonic-gate
267*0Sstevel@tonic-gate good_compose = kbtrans_do_compose(lower,
268*0Sstevel@tonic-gate lower->kbtrans_compose_key, entry,
269*0Sstevel@tonic-gate &result_iso);
270*0Sstevel@tonic-gate if (good_compose) {
271*0Sstevel@tonic-gate if (lower->kbtrans_compat)
272*0Sstevel@tonic-gate result_iso += ISO_FIRST;
273*0Sstevel@tonic-gate else
274*0Sstevel@tonic-gate result_iso += EUC_FIRST;
275*0Sstevel@tonic-gate cb->kc_keypressed(lower->kbtrans_upper,
276*0Sstevel@tonic-gate entrytype, key, result_iso);
277*0Sstevel@tonic-gate }
278*0Sstevel@tonic-gate return;
279*0Sstevel@tonic-gate
280*0Sstevel@tonic-gate case FLTACCENT:
281*0Sstevel@tonic-gate if (newstate == KEY_RELEASED)
282*0Sstevel@tonic-gate
283*0Sstevel@tonic-gate return;
284*0Sstevel@tonic-gate
285*0Sstevel@tonic-gate /* next state is "normal" */
286*0Sstevel@tonic-gate lower->kbtrans_state = NORMAL;
287*0Sstevel@tonic-gate for (i = 0;
288*0Sstevel@tonic-gate (lower->kbtrans_fltaccent_table[i].fa_entry
289*0Sstevel@tonic-gate != lower->kbtrans_fltaccent_entry) ||
290*0Sstevel@tonic-gate (lower->kbtrans_fltaccent_table[i].ascii != entry);
291*0Sstevel@tonic-gate i++) {
292*0Sstevel@tonic-gate if (lower->kbtrans_fltaccent_table[i].fa_entry
293*0Sstevel@tonic-gate == 0) {
294*0Sstevel@tonic-gate /* Invalid second key: ignore key */
295*0Sstevel@tonic-gate
296*0Sstevel@tonic-gate return;
297*0Sstevel@tonic-gate }
298*0Sstevel@tonic-gate }
299*0Sstevel@tonic-gate
300*0Sstevel@tonic-gate cb->kc_keypressed(lower->kbtrans_upper, entrytype,
301*0Sstevel@tonic-gate key, (lower->kbtrans_compat ?
302*0Sstevel@tonic-gate ISO_FIRST : EUC_FIRST) +
303*0Sstevel@tonic-gate lower->kbtrans_fltaccent_table[i].iso);
304*0Sstevel@tonic-gate
305*0Sstevel@tonic-gate return;
306*0Sstevel@tonic-gate }
307*0Sstevel@tonic-gate }
308*0Sstevel@tonic-gate
309*0Sstevel@tonic-gate /*
310*0Sstevel@tonic-gate * If the key is going down, and it's not one of the keys that doesn't
311*0Sstevel@tonic-gate * auto-repeat, set up the auto-repeat timeout.
312*0Sstevel@tonic-gate *
313*0Sstevel@tonic-gate * The keys that don't auto-repeat are the Compose key,
314*0Sstevel@tonic-gate * the shift keys, the "bucky bit" keys, the "floating accent" keys,
315*0Sstevel@tonic-gate * and the function keys when in TR_EVENT mode.
316*0Sstevel@tonic-gate */
317*0Sstevel@tonic-gate if (newstate == KEY_PRESSED && entrytype != SHIFTKEYS &&
318*0Sstevel@tonic-gate entrytype != BUCKYBITS && entrytype != FUNNY &&
319*0Sstevel@tonic-gate entrytype != FA_CLASS) {
320*0Sstevel@tonic-gate
321*0Sstevel@tonic-gate if (lower->kbtrans_repeatkey != key) {
322*0Sstevel@tonic-gate cb->kc_cancel_repeat(lower->kbtrans_upper);
323*0Sstevel@tonic-gate cb->kc_setup_repeat(lower->kbtrans_upper, entrytype,
324*0Sstevel@tonic-gate key);
325*0Sstevel@tonic-gate }
326*0Sstevel@tonic-gate /* key going up */
327*0Sstevel@tonic-gate } else if (key == lower->kbtrans_repeatkey) {
328*0Sstevel@tonic-gate
329*0Sstevel@tonic-gate cb->kc_cancel_repeat(lower->kbtrans_upper);
330*0Sstevel@tonic-gate }
331*0Sstevel@tonic-gate
332*0Sstevel@tonic-gate if (newstate == KEY_RELEASED) {
333*0Sstevel@tonic-gate cb->kc_keyreleased(lower->kbtrans_upper, key);
334*0Sstevel@tonic-gate }
335*0Sstevel@tonic-gate
336*0Sstevel@tonic-gate /*
337*0Sstevel@tonic-gate * We assume here that keys other than shift keys and bucky keys have
338*0Sstevel@tonic-gate * entries in the "up" table that cause nothing to be done, and thus we
339*0Sstevel@tonic-gate * don't have to check for newstate == KEY_RELEASED.
340*0Sstevel@tonic-gate */
341*0Sstevel@tonic-gate switch (entrytype) {
342*0Sstevel@tonic-gate
343*0Sstevel@tonic-gate case 0x0: /* regular key */
344*0Sstevel@tonic-gate cb->kc_keypressed(lower->kbtrans_upper, entrytype, key,
345*0Sstevel@tonic-gate entry | lower->kbtrans_buckybits);
346*0Sstevel@tonic-gate break;
347*0Sstevel@tonic-gate
348*0Sstevel@tonic-gate case SHIFTKEYS: {
349*0Sstevel@tonic-gate uint_t shiftbit = 1 << (entry & 0x0F);
350*0Sstevel@tonic-gate
351*0Sstevel@tonic-gate /* Modify toggle state (see toggle processing above) */
352*0Sstevel@tonic-gate if (shiftbit & lower->kbtrans_keyboard->k_toggleshifts) {
353*0Sstevel@tonic-gate if (newstate == KEY_RELEASED) {
354*0Sstevel@tonic-gate if (shiftbit == CAPSMASK) {
355*0Sstevel@tonic-gate lower->kbtrans_led_state &=
356*0Sstevel@tonic-gate ~LED_CAPS_LOCK;
357*0Sstevel@tonic-gate
358*0Sstevel@tonic-gate cb->kc_setled(lower->kbtrans_upper);
359*0Sstevel@tonic-gate
360*0Sstevel@tonic-gate } else if (shiftbit == NUMLOCKMASK) {
361*0Sstevel@tonic-gate lower->kbtrans_led_state &=
362*0Sstevel@tonic-gate ~LED_NUM_LOCK;
363*0Sstevel@tonic-gate
364*0Sstevel@tonic-gate cb->kc_setled(lower->kbtrans_upper);
365*0Sstevel@tonic-gate }
366*0Sstevel@tonic-gate lower->kbtrans_togglemask &= ~shiftbit;
367*0Sstevel@tonic-gate } else {
368*0Sstevel@tonic-gate if (shiftbit == CAPSMASK) {
369*0Sstevel@tonic-gate lower->kbtrans_led_state |=
370*0Sstevel@tonic-gate LED_CAPS_LOCK;
371*0Sstevel@tonic-gate
372*0Sstevel@tonic-gate cb->kc_setled(lower->kbtrans_upper);
373*0Sstevel@tonic-gate } else if (shiftbit == NUMLOCKMASK) {
374*0Sstevel@tonic-gate lower->kbtrans_led_state |=
375*0Sstevel@tonic-gate LED_NUM_LOCK;
376*0Sstevel@tonic-gate
377*0Sstevel@tonic-gate cb->kc_setled(lower->kbtrans_upper);
378*0Sstevel@tonic-gate }
379*0Sstevel@tonic-gate lower->kbtrans_togglemask |= shiftbit;
380*0Sstevel@tonic-gate }
381*0Sstevel@tonic-gate }
382*0Sstevel@tonic-gate
383*0Sstevel@tonic-gate if (newstate == KEY_RELEASED)
384*0Sstevel@tonic-gate lower->kbtrans_shiftmask &= ~shiftbit;
385*0Sstevel@tonic-gate else
386*0Sstevel@tonic-gate lower->kbtrans_shiftmask |= shiftbit;
387*0Sstevel@tonic-gate
388*0Sstevel@tonic-gate if (newstate == KEY_PRESSED) {
389*0Sstevel@tonic-gate cb->kc_keypressed(lower->kbtrans_upper, entrytype, key,
390*0Sstevel@tonic-gate entry);
391*0Sstevel@tonic-gate }
392*0Sstevel@tonic-gate
393*0Sstevel@tonic-gate break;
394*0Sstevel@tonic-gate }
395*0Sstevel@tonic-gate
396*0Sstevel@tonic-gate case BUCKYBITS:
397*0Sstevel@tonic-gate lower->kbtrans_buckybits ^= 1 << (7 + (entry & 0x0F));
398*0Sstevel@tonic-gate
399*0Sstevel@tonic-gate if (newstate == KEY_PRESSED) {
400*0Sstevel@tonic-gate cb->kc_keypressed(lower->kbtrans_upper, entrytype, key,
401*0Sstevel@tonic-gate entry);
402*0Sstevel@tonic-gate }
403*0Sstevel@tonic-gate
404*0Sstevel@tonic-gate break;
405*0Sstevel@tonic-gate
406*0Sstevel@tonic-gate case FUNNY:
407*0Sstevel@tonic-gate switch (entry) {
408*0Sstevel@tonic-gate case NOP:
409*0Sstevel@tonic-gate break;
410*0Sstevel@tonic-gate
411*0Sstevel@tonic-gate case IDLE:
412*0Sstevel@tonic-gate /* Fall thru into RESET code */
413*0Sstevel@tonic-gate /* FALLTHRU */
414*0Sstevel@tonic-gate case RESET:
415*0Sstevel@tonic-gate case ERROR:
416*0Sstevel@tonic-gate lower->kbtrans_shiftmask &=
417*0Sstevel@tonic-gate lower->kbtrans_keyboard->k_idleshifts;
418*0Sstevel@tonic-gate
419*0Sstevel@tonic-gate lower->kbtrans_shiftmask |=
420*0Sstevel@tonic-gate lower->kbtrans_togglemask;
421*0Sstevel@tonic-gate
422*0Sstevel@tonic-gate lower->kbtrans_buckybits &=
423*0Sstevel@tonic-gate lower->kbtrans_keyboard->k_idlebuckys;
424*0Sstevel@tonic-gate
425*0Sstevel@tonic-gate cb->kc_cancel_repeat(lower->kbtrans_upper);
426*0Sstevel@tonic-gate
427*0Sstevel@tonic-gate cb->kc_keypressed(lower->kbtrans_upper, entrytype, key,
428*0Sstevel@tonic-gate entry);
429*0Sstevel@tonic-gate
430*0Sstevel@tonic-gate break;
431*0Sstevel@tonic-gate
432*0Sstevel@tonic-gate
433*0Sstevel@tonic-gate case COMPOSE:
434*0Sstevel@tonic-gate lower->kbtrans_state = COMPOSE1;
435*0Sstevel@tonic-gate lower->kbtrans_led_state |= LED_COMPOSE;
436*0Sstevel@tonic-gate cb->kc_setled(lower->kbtrans_upper);
437*0Sstevel@tonic-gate break;
438*0Sstevel@tonic-gate /*
439*0Sstevel@tonic-gate * Remember when adding new entries that,
440*0Sstevel@tonic-gate * if they should NOT auto-repeat,
441*0Sstevel@tonic-gate * they should be put into the IF statement
442*0Sstevel@tonic-gate * just above this switch block.
443*0Sstevel@tonic-gate */
444*0Sstevel@tonic-gate default:
445*0Sstevel@tonic-gate /* Ignore it */
446*0Sstevel@tonic-gate break;
447*0Sstevel@tonic-gate }
448*0Sstevel@tonic-gate break;
449*0Sstevel@tonic-gate
450*0Sstevel@tonic-gate case FA_CLASS:
451*0Sstevel@tonic-gate if (lower->kbtrans_state == NORMAL) {
452*0Sstevel@tonic-gate lower->kbtrans_fltaccent_entry = entry;
453*0Sstevel@tonic-gate lower->kbtrans_state = FLTACCENT;
454*0Sstevel@tonic-gate }
455*0Sstevel@tonic-gate break;
456*0Sstevel@tonic-gate
457*0Sstevel@tonic-gate case STRING:
458*0Sstevel@tonic-gate cb->kc_keypressed(lower->kbtrans_upper, entrytype, key, entry);
459*0Sstevel@tonic-gate
460*0Sstevel@tonic-gate break;
461*0Sstevel@tonic-gate
462*0Sstevel@tonic-gate case FUNCKEYS:
463*0Sstevel@tonic-gate cb->kc_keypressed(lower->kbtrans_upper, entrytype, key, entry);
464*0Sstevel@tonic-gate
465*0Sstevel@tonic-gate break;
466*0Sstevel@tonic-gate
467*0Sstevel@tonic-gate /*
468*0Sstevel@tonic-gate * Remember when adding new entries that,
469*0Sstevel@tonic-gate * if they should NOT auto-repeat,
470*0Sstevel@tonic-gate * they should be put into the IF statement
471*0Sstevel@tonic-gate * just above this switch block.
472*0Sstevel@tonic-gate */
473*0Sstevel@tonic-gate case PADKEYS:
474*0Sstevel@tonic-gate cb->kc_keypressed(lower->kbtrans_upper, entrytype, key, entry);
475*0Sstevel@tonic-gate
476*0Sstevel@tonic-gate break;
477*0Sstevel@tonic-gate }
478*0Sstevel@tonic-gate }
479*0Sstevel@tonic-gate
480*0Sstevel@tonic-gate /*
481*0Sstevel@tonic-gate * kbtrans_do_compose:
482*0Sstevel@tonic-gate * Given a two key compose sequence, lookup the iso equivalent and put
483*0Sstevel@tonic-gate * the result in the result_iso_ptr.
484*0Sstevel@tonic-gate */
485*0Sstevel@tonic-gate static boolean_t
kbtrans_do_compose(struct kbtrans_lower * lower,ushort_t first_entry,ushort_t second_entry,ushort_t * result_iso_ptr)486*0Sstevel@tonic-gate kbtrans_do_compose(struct kbtrans_lower *lower,
487*0Sstevel@tonic-gate ushort_t first_entry,
488*0Sstevel@tonic-gate ushort_t second_entry,
489*0Sstevel@tonic-gate ushort_t *result_iso_ptr)
490*0Sstevel@tonic-gate {
491*0Sstevel@tonic-gate struct compose_sequence_t *ptr;
492*0Sstevel@tonic-gate ushort_t tmp;
493*0Sstevel@tonic-gate
494*0Sstevel@tonic-gate /*
495*0Sstevel@tonic-gate * Validate the second keystroke.
496*0Sstevel@tonic-gate */
497*0Sstevel@tonic-gate if (second_entry >= ASCII_SET_SIZE)
498*0Sstevel@tonic-gate return (B_FALSE);
499*0Sstevel@tonic-gate
500*0Sstevel@tonic-gate if (lower->kbtrans_compose_map[second_entry] < 0)
501*0Sstevel@tonic-gate return (B_FALSE);
502*0Sstevel@tonic-gate
503*0Sstevel@tonic-gate /*
504*0Sstevel@tonic-gate * Get them in code order, rather than press order.
505*0Sstevel@tonic-gate */
506*0Sstevel@tonic-gate if (first_entry > second_entry) {
507*0Sstevel@tonic-gate tmp = first_entry;
508*0Sstevel@tonic-gate first_entry = second_entry;
509*0Sstevel@tonic-gate second_entry = tmp;
510*0Sstevel@tonic-gate }
511*0Sstevel@tonic-gate
512*0Sstevel@tonic-gate ptr = lower->kbtrans_compose_table +
513*0Sstevel@tonic-gate lower->kbtrans_compose_map[first_entry];
514*0Sstevel@tonic-gate
515*0Sstevel@tonic-gate while (ptr->first == first_entry) {
516*0Sstevel@tonic-gate if (ptr->second == second_entry) {
517*0Sstevel@tonic-gate *result_iso_ptr = ptr->iso;
518*0Sstevel@tonic-gate
519*0Sstevel@tonic-gate return (B_TRUE);
520*0Sstevel@tonic-gate }
521*0Sstevel@tonic-gate ptr++;
522*0Sstevel@tonic-gate }
523*0Sstevel@tonic-gate return (B_FALSE);
524*0Sstevel@tonic-gate }
525*0Sstevel@tonic-gate
526*0Sstevel@tonic-gate
527*0Sstevel@tonic-gate /*
528*0Sstevel@tonic-gate * kbtrans_find_entry:
529*0Sstevel@tonic-gate * This routine finds the entry corresponding to the current shift
530*0Sstevel@tonic-gate * state and keycode.
531*0Sstevel@tonic-gate */
532*0Sstevel@tonic-gate unsigned short *
kbtrans_find_entry(struct kbtrans_lower * lower,register uint_t mask,kbtrans_key_t key_station)533*0Sstevel@tonic-gate kbtrans_find_entry(struct kbtrans_lower *lower,
534*0Sstevel@tonic-gate register uint_t mask,
535*0Sstevel@tonic-gate kbtrans_key_t key_station)
536*0Sstevel@tonic-gate {
537*0Sstevel@tonic-gate register struct keyboard *kp;
538*0Sstevel@tonic-gate keymap_entry_t *km;
539*0Sstevel@tonic-gate struct exception_map *ex;
540*0Sstevel@tonic-gate
541*0Sstevel@tonic-gate kp = lower->kbtrans_keyboard;
542*0Sstevel@tonic-gate
543*0Sstevel@tonic-gate if (kp == NULL)
544*0Sstevel@tonic-gate return (NULL);
545*0Sstevel@tonic-gate
546*0Sstevel@tonic-gate if (key_station < 0 || key_station >= kp->k_keymap_size)
547*0Sstevel@tonic-gate return (NULL);
548*0Sstevel@tonic-gate
549*0Sstevel@tonic-gate ex = kp->k_except;
550*0Sstevel@tonic-gate if (ex != NULL) {
551*0Sstevel@tonic-gate for (; ex->exc_care != 0; ex++) {
552*0Sstevel@tonic-gate if ((mask & ex->exc_care) == ex->exc_mask &&
553*0Sstevel@tonic-gate key_station == ex->exc_key)
554*0Sstevel@tonic-gate return (&ex->exc_entry);
555*0Sstevel@tonic-gate }
556*0Sstevel@tonic-gate }
557*0Sstevel@tonic-gate
558*0Sstevel@tonic-gate if (mask & UPMASK)
559*0Sstevel@tonic-gate km = kp->k_up;
560*0Sstevel@tonic-gate else if (mask & NUMLOCKMASK)
561*0Sstevel@tonic-gate km = kp->k_numlock;
562*0Sstevel@tonic-gate else if (mask & CTRLMASK)
563*0Sstevel@tonic-gate km = kp->k_control;
564*0Sstevel@tonic-gate else if (mask & ALTGRAPHMASK)
565*0Sstevel@tonic-gate km = kp->k_altgraph;
566*0Sstevel@tonic-gate else if (mask & SHIFTMASK)
567*0Sstevel@tonic-gate km = kp->k_shifted;
568*0Sstevel@tonic-gate else if (mask & CAPSMASK)
569*0Sstevel@tonic-gate km = kp->k_caps;
570*0Sstevel@tonic-gate else km = kp->k_normal;
571*0Sstevel@tonic-gate
572*0Sstevel@tonic-gate return (&km[key_station]);
573*0Sstevel@tonic-gate }
574*0Sstevel@tonic-gate
575*0Sstevel@tonic-gate #ifdef DEBUG
576*0Sstevel@tonic-gate /*ARGSUSED*/
577*0Sstevel@tonic-gate void
kbtrans_dprintf(void * un,const char * fmt,...)578*0Sstevel@tonic-gate kbtrans_dprintf(void *un, const char *fmt, ...)
579*0Sstevel@tonic-gate {
580*0Sstevel@tonic-gate char buf[256];
581*0Sstevel@tonic-gate va_list ap;
582*0Sstevel@tonic-gate
583*0Sstevel@tonic-gate va_start(ap, fmt);
584*0Sstevel@tonic-gate (void) vsprintf(buf, fmt, ap);
585*0Sstevel@tonic-gate va_end(ap);
586*0Sstevel@tonic-gate
587*0Sstevel@tonic-gate cmn_err(CE_CONT, "kbtrans: %s", buf);
588*0Sstevel@tonic-gate }
589*0Sstevel@tonic-gate #endif
590