1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* VUIDMICE module: put mouse events into vuid format
*/
#include <sys/param.h>
#include <sys/stream.h>
#include <sys/stropts.h>
#include <sys/strsun.h>
#include <sys/errno.h>
#include <sys/debug.h>
#include <sys/cmn_err.h>
#include <sys/sad.h>
#include <sys/vuid_event.h>
#include "vuidmice.h"
#include <sys/vuid_wheel.h>
#include <sys/msio.h>
#include <sys/conf.h>
#include <sys/modctl.h>
#include <sys/kmem.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
static int vuidmice_open(queue_t *const, const dev_t *const,
const int, const int, const cred_t *const);
static int vuidmice_close(queue_t *const, const int, const cred_t *const);
static int vuidmice_rput(queue_t *const, mblk_t *);
static int vuidmice_rsrv(queue_t *const);
static int vuidmice_wput(queue_t *const, mblk_t *);
static void vuidmice_miocdata(queue_t *const, mblk_t *);
static int vuidmice_handle_wheel_resolution_ioctl(queue_t *const,
mblk_t *, int);
static int vuidmice_service_wheel_info(mblk_t *);
static int vuidmice_service_wheel_state(queue_t *, mblk_t *, uint_t);
void VUID_QUEUE(queue_t *const, mblk_t *);
int VUID_OPEN(queue_t *const);
void VUID_CLOSE(queue_t *const);
static kmutex_t vuidmice_lock;
static struct module_info vuidmice_iinfo = {
0,
VUID_NAME,
0,
INFPSZ,
1000,
100
};
static struct qinit vuidmice_rinit = {
vuidmice_rput,
vuidmice_rsrv,
vuidmice_open,
vuidmice_close,
NULL,
&vuidmice_iinfo,
NULL
};
static struct module_info vuidmice_oinfo = {
0,
VUID_NAME,
0,
INFPSZ,
1000,
100
};
static struct qinit vuidmice_winit = {
vuidmice_wput,
NULL,
NULL,
NULL,
NULL,
&vuidmice_oinfo,
NULL
};
struct streamtab vuidmice_info = {
&vuidmice_rinit,
&vuidmice_winit,
NULL,
NULL
};
/*
* This is the loadable module wrapper.
*/
/*
* D_MTQPAIR effectively makes the module single threaded.
* There can be only one thread active in the module at any time.
* It may be a read or write thread.
*/
#define VUIDMICE_CONF_FLAG (D_MP | D_MTQPAIR)
static struct fmodsw fsw = {
VUID_NAME,
&vuidmice_info,
VUIDMICE_CONF_FLAG
};
static struct modlstrmod modlstrmod = {
&mod_strmodops,
"mouse events to vuid events",
&fsw
};
/*
* Module linkage information for the kernel.
*/
static struct modlinkage modlinkage = {
MODREV_1,
&modlstrmod,
NULL
};
static int module_open = 0; /* allow only one open of this module */
int
_init(void)
{
register int rc;
mutex_init(&vuidmice_lock, NULL, MUTEX_DEFAULT, NULL);
if ((rc = mod_install(&modlinkage)) != 0) {
mutex_destroy(&vuidmice_lock);
}
return (rc);
}
int
_fini(void)
{
register int rc;
if ((rc = mod_remove(&modlinkage)) == 0)
mutex_destroy(&vuidmice_lock);
return (rc);
}
int
_info(struct modinfo *modinfop)
{
return (mod_info(&modlinkage, modinfop));
}
/* ARGSUSED1 */
static int
vuidmice_open(queue_t *const qp, const dev_t *const devp,
const int oflag, const int sflag, const cred_t *const crp)
{
if (qp->q_ptr != NULL)
return (0); /* reopen */
mutex_enter(&vuidmice_lock);
/* Allow only 1 open of this module */
if (module_open) {
mutex_exit(&vuidmice_lock);
return (EBUSY);
}
module_open++;
mutex_exit(&vuidmice_lock);
/*
* Both the read and write queues share the same state structures.
*/
qp->q_ptr = kmem_zalloc(sizeof (struct MouseStateInfo), KM_SLEEP);
WR(qp)->q_ptr = qp->q_ptr;
/* initialize state */
STATEP->format = VUID_NATIVE;
qprocson(qp);
#ifdef VUID_OPEN
if (VUID_OPEN(qp) != 0) {
qprocsoff(qp);
mutex_enter(&vuidmice_lock);
module_open--;
mutex_exit(&vuidmice_lock);
kmem_free(qp->q_ptr, sizeof (struct MouseStateInfo));
qp->q_ptr = NULL;
return (ENXIO);
}
#endif
return (0);
}
/* ARGSUSED1 */
static int
vuidmice_close(queue_t *const qp, const int flag, const cred_t *const crp)
{
ASSERT(qp != NULL);
qprocsoff(qp);
flushq(qp, FLUSHALL);
flushq(OTHERQ(qp), FLUSHALL);
#ifdef VUID_CLOSE
VUID_CLOSE(qp);
#endif
mutex_enter(&vuidmice_lock);
module_open--;
mutex_exit(&vuidmice_lock);
kmem_free(qp->q_ptr, sizeof (struct MouseStateInfo));
qp->q_ptr = NULL;
return (0);
}
/*
* Put procedure for input from driver end of stream (read queue).
*/
static int
vuidmice_rput(queue_t *const qp, mblk_t *mp)
{
ASSERT(qp != NULL);
ASSERT(mp != NULL);
/*
* Handle all the related high priority messages here, hence
* should spend the least amount of time here.
*/
if (DB_TYPE(mp) == M_DATA) {
if ((int)STATEP->format == VUID_FIRM_EVENT)
return (putq(qp, mp)); /* queue message & return */
} else if (DB_TYPE(mp) == M_FLUSH) {
if (*mp->b_rptr & FLUSHR)
flushq(qp, FLUSHALL);
}
putnext(qp, mp); /* pass it on */
return (0);
}
static int
vuidmice_rsrv(queue_t *const qp)
{
register mblk_t *mp;
ASSERT(qp != NULL);
while ((mp = getq(qp)) != NULL) {
ASSERT(DB_TYPE(mp) == M_DATA);
if (!canputnext(qp))
return (putbq(qp, mp)); /* read side is blocked */
switch (DB_TYPE(mp)) {
case M_DATA:
if ((int)STATEP->format == VUID_FIRM_EVENT)
(void) VUID_QUEUE(qp, mp);
else
(void) putnext(qp, mp);
break;
default:
cmn_err(CE_WARN,
"vuidmice_rsrv: bad message type (0x%x)\n",
DB_TYPE(mp));
(void) putnext(qp, mp);
break;
}
}
return (0);
}
/*
* Put procedure for write from user end of stream (write queue).
*/
static int
vuidmice_wput(queue_t *const qp, mblk_t *mp)
{
int error = 0;
ASSERT(qp != NULL);
ASSERT(mp != NULL);
/*
* Handle all the related high priority messages here, hence
* should spend the least amount of time here.
*/
switch (DB_TYPE(mp)) { /* handle hi pri messages here */
case M_FLUSH:
if (*mp->b_rptr & FLUSHW)
flushq(qp, FLUSHALL);
putnext(qp, mp); /* pass it on */
return (0);
case M_IOCTL: {
struct iocblk *iocbp = (void *)mp->b_rptr;
switch (iocbp->ioc_cmd) {
case VUIDSFORMAT:
/*
* VUIDSFORMAT is known to the stream head and thus
* is guaranteed to be an I_STR ioctl.
*/
if (iocbp->ioc_count == TRANSPARENT) {
miocnak(qp, mp, 0, EINVAL);
return (0);
} else {
int format_type;
error = miocpullup(mp, sizeof (int));
if (error != 0) {
miocnak(qp, mp, 0, error);
return (0);
}
format_type =
*(int *)(void *)mp->b_cont->b_rptr;
STATEP->format = (uchar_t)format_type;
iocbp->ioc_rval = 0;
iocbp->ioc_count = 0;
iocbp->ioc_error = 0;
mp->b_datap->db_type = M_IOCACK;
}
/* return buffer to pool ASAP */
if (mp->b_cont) {
freemsg(mp->b_cont);
mp->b_cont = NULL;
}
qreply(qp, mp);
return (0);
case VUIDGFORMAT:
/* return buffer to pool ASAP */
if (mp->b_cont) {
freemsg(mp->b_cont); /* over written below */
mp->b_cont = NULL;
}
/*
* VUIDGFORMAT is known to the stream head and thus
* is guaranteed to be an I_STR ioctl.
*/
if (iocbp->ioc_count == TRANSPARENT) {
miocnak(qp, mp, 0, EINVAL);
return (0);
}
mp->b_cont = allocb(sizeof (int), BPRI_MED);
if (mp->b_cont == NULL) {
miocnak(qp, mp, 0, EAGAIN);
return (0);
}
*(int *)(void *)mp->b_cont->b_rptr =
(int)STATEP->format;
mp->b_cont->b_wptr += sizeof (int);
iocbp->ioc_count = sizeof (int);
mp->b_datap->db_type = M_IOCACK;
qreply(qp, mp);
return (0);
case VUID_NATIVE:
case VUIDSADDR:
case VUIDGADDR:
miocnak(qp, mp, 0, ENOTTY);
return (0);
case MSIOBUTTONS:
/* return buffer to pool ASAP */
if (mp->b_cont) {
freemsg(mp->b_cont); /* over written below */
mp->b_cont = NULL;
}
/*
* MSIOBUTTONS is known to streamio.c and this
* is assume to be non-I_STR & non-TRANSPARENT ioctl
*/
if (iocbp->ioc_count == TRANSPARENT) {
miocnak(qp, mp, 0, EINVAL);
return (0);
}
if (STATEP->nbuttons == 0) {
miocnak(qp, mp, 0, EINVAL);
return (0);
}
mp->b_cont = allocb(sizeof (int), BPRI_MED);
if (mp->b_cont == NULL) {
miocnak(qp, mp, 0, EAGAIN);
return (0);
}
*(int *)(void *)mp->b_cont->b_rptr =
(int)STATEP->nbuttons;
mp->b_cont->b_wptr += sizeof (int);
iocbp->ioc_count = sizeof (int);
mp->b_datap->db_type = M_IOCACK;
qreply(qp, mp);
return (0);
/*
* New IOCTL support. Since it's explicitly mentioned
* that you can't add more ioctls to stream head's
* hard coded list, we have to do the transparent
* ioctl processing which is not very exciting.
*/
case VUIDGWHEELCOUNT:
case VUIDGWHEELINFO:
case VUIDGWHEELSTATE:
case VUIDSWHEELSTATE:
case MSIOSRESOLUTION:
error = vuidmice_handle_wheel_resolution_ioctl(qp,
mp, iocbp->ioc_cmd);
if (!error) {
return (0);
} else {
miocnak(qp, mp, 0, error);
return (0);
}
default:
putnext(qp, mp); /* nothing to process here */
return (0);
}
} /* End of case M_IOCTL */
case M_IOCDATA:
vuidmice_miocdata(qp, mp);
return (0);
default:
putnext(qp, mp); /* pass it on */
return (0);
}
/*NOTREACHED*/
}
void
VUID_PUTNEXT(queue_t *const qp, uchar_t event_id, uchar_t event_pair_type,
uchar_t event_pair, int event_value)
{
int strikes = 1;
mblk_t *bp;
Firm_event *fep;
/*
* Give this event 3 chances to allocate blocks,
* otherwise discard this mouse event. 3 Strikes and you're out.
*/
while ((bp = allocb((int)sizeof (Firm_event), BPRI_HI)) == NULL) {
if (++strikes > 3)
return;
drv_usecwait(10);
}
fep = (void *)bp->b_wptr;
fep->id = vuid_id_addr(VKEY_FIRST) | vuid_id_offset(event_id);
fep->pair_type = event_pair_type;
fep->pair = event_pair;
fep->value = event_value;
uniqtime32(&fep->time);
bp->b_wptr += sizeof (Firm_event);
if (canput(qp->q_next))
putnext(qp, bp);
else
(void) putbq(qp, bp); /* read side is blocked */
}
/*
* vuidmice_miocdata
* M_IOCDATA processing for IOCTL's: VUIDGWHEELCOUNT, VUIDGWHEELINFO,
* VUIDGWHEELSTATE, VUIDSWHEELSTATE & MSIOSRESOLUTION.
*/
static void
vuidmice_miocdata(queue_t *qp, mblk_t *mp)
{
struct copyresp *copyresp;
struct iocblk *iocbp;
mblk_t *ioctmp;
mblk_t *datap;
Mouse_iocstate_t *Mouseioc;
size_t size;
int err = 0;
copyresp = (void *)mp->b_rptr;
iocbp = (void *)mp->b_rptr;
if (copyresp->cp_rval) {
err = EAGAIN;
goto err;
}
switch (copyresp->cp_cmd) {
case VUIDGWHEELCOUNT:
mp->b_datap->db_type = M_IOCACK;
mp->b_wptr = mp->b_rptr + sizeof (struct iocblk);
iocbp->ioc_error = 0;
iocbp->ioc_count = 0;
iocbp->ioc_rval = 0;
if (mp->b_cont != NULL) {
freemsg(mp->b_cont);
mp->b_cont = NULL;
}
break;
case VUIDGWHEELINFO:
case VUIDGWHEELSTATE:
ioctmp = copyresp->cp_private;
Mouseioc = (void *)ioctmp->b_rptr;
if (Mouseioc->ioc_state == GETSTRUCT) {
if (mp->b_cont == NULL) {
err = EINVAL;
break;
}
datap = mp->b_cont;
if (copyresp->cp_cmd == VUIDGWHEELSTATE) {
err = vuidmice_service_wheel_state(qp, datap,
VUIDGWHEELSTATE);
} else {
err = vuidmice_service_wheel_info(datap);
}
if (err) {
break;
}
if (copyresp->cp_cmd == VUIDGWHEELSTATE) {
size = sizeof (wheel_state);
} else {
size = sizeof (wheel_info);
}
Mouseioc->ioc_state = GETRESULT;
ASSERT(Mouseioc->u_addr != NULL);
mcopyout(mp, ioctmp, size, Mouseioc->u_addr, NULL);
} else if (Mouseioc->ioc_state == GETRESULT) {
freemsg(ioctmp);
mp->b_datap->db_type = M_IOCACK;
mp->b_wptr = mp->b_rptr + sizeof (struct iocblk);
iocbp->ioc_error = 0;
iocbp->ioc_count = 0;
iocbp->ioc_rval = 0;
if (mp->b_cont != NULL) {
freemsg(mp->b_cont);
mp->b_cont = NULL;
}
}
break;
case VUIDSWHEELSTATE:
case MSIOSRESOLUTION:
ioctmp = copyresp->cp_private;
Mouseioc = (void *)ioctmp->b_rptr;
if (mp->b_cont == NULL) {
err = EINVAL;
break;
}
datap = mp->b_cont;
if (copyresp->cp_cmd == VUIDSWHEELSTATE) {
err = vuidmice_service_wheel_state(qp,
datap, VUIDSWHEELSTATE);
}
if (err) {
break;
}
if (mp->b_cont) {
freemsg(mp->b_cont);
mp->b_cont = NULL;
}
freemsg(ioctmp);
iocbp->ioc_count = 0;
iocbp->ioc_error = 0;
iocbp->ioc_rval = 0;
mp->b_datap->db_type = M_IOCACK;
break;
default:
err = EINVAL;
break;
}
err:
if (err) {
mp->b_datap->db_type = M_IOCNAK;
if (mp->b_cont) {
freemsg(mp->b_cont);
mp->b_cont = NULL;
}
if (copyresp->cp_private) {
freemsg(copyresp->cp_private);
copyresp->cp_private = NULL;
}
iocbp->ioc_count = 0;
iocbp->ioc_error = err;
}
qreply(qp, mp);
}
/*
* vuidmice_handle_wheel_resolution_ioctl
* Handle wheel mouse and MSIOSRESOLUTION ioctls.
*
* Here we also support non-transparent way of these ioctls
* just like usb mouse driver does, so the consms module is
* very simple to deal with these ioctls.
*/
static int
vuidmice_handle_wheel_resolution_ioctl(queue_t *qp, mblk_t *mp, int cmd)
{
int err = 0;
Mouse_iocstate_t *Mouseioc;
caddr_t useraddr;
size_t size;
mblk_t *ioctmp;
mblk_t *datap;
struct iocblk *iocbp = (void *)mp->b_rptr;
if (iocbp->ioc_count == TRANSPARENT) {
if (mp->b_cont == NULL)
return (EINVAL);
useraddr = *((caddr_t *)(void *)mp->b_cont->b_rptr);
switch (cmd) {
case VUIDGWHEELCOUNT:
size = sizeof (int);
if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL)
return (EAGAIN);
*((int *)(void *)datap->b_wptr) =
STATEP->vuid_mouse_mode;
mcopyout(mp, NULL, size, NULL, datap);
qreply(qp, mp);
return (err);
case VUIDGWHEELINFO:
size = sizeof (wheel_info);
break;
case VUIDSWHEELSTATE:
case VUIDGWHEELSTATE:
size = sizeof (wheel_state);
break;
case MSIOSRESOLUTION:
size = sizeof (Ms_screen_resolution);
break;
}
if ((ioctmp = allocb(sizeof (Mouse_iocstate_t),
BPRI_MED)) == NULL)
return (EAGAIN);
Mouseioc = (void *)ioctmp->b_rptr;
Mouseioc->ioc_state = GETSTRUCT;
Mouseioc->u_addr = useraddr;
ioctmp->b_wptr = ioctmp->b_rptr + sizeof (Mouse_iocstate_t);
mcopyin(mp, ioctmp, size, NULL);
qreply(qp, mp);
return (err);
} else {
switch (cmd) {
case VUIDGWHEELCOUNT:
if (mp->b_cont) {
freemsg(mp->b_cont);
mp->b_cont = NULL;
}
if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL) {
err = EAGAIN;
break;
}
*((int *)(void *)datap->b_wptr) =
STATEP->vuid_mouse_mode;
datap->b_wptr += sizeof (int);
mp->b_cont = datap;
break;
case VUIDGWHEELINFO:
if (mp->b_cont == NULL ||
iocbp->ioc_count != sizeof (wheel_info)) {
err = EINVAL;
break;
}
datap = mp->b_cont;
err = vuidmice_service_wheel_info(datap);
break;
case VUIDSWHEELSTATE:
case VUIDGWHEELSTATE:
if (mp->b_cont == NULL ||
iocbp->ioc_count != sizeof (wheel_state)) {
err = EINVAL;
break;
}
datap = mp->b_cont;
err = vuidmice_service_wheel_state(qp, datap, cmd);
break;
case MSIOSRESOLUTION:
/*
* Now we just make Xserver and
* the virtual mouse happy. Of course,
* the screen resolution value may
* be used later for absolute PS/2 mouse.
*/
err = 0;
break;
}
if (!err) {
mp->b_datap->db_type = M_IOCACK;
iocbp->ioc_rval = 0;
iocbp->ioc_error = 0;
qreply(qp, mp);
}
return (err);
}
}
static int
vuidmice_service_wheel_info(register mblk_t *datap)
{
wheel_info *wi;
int err = 0;
wi = (void *)datap->b_rptr;
if (wi->vers != VUID_WHEEL_INFO_VERS) {
err = EINVAL;
return (err);
}
if (wi->id > (VUIDMICE_NUM_WHEELS - 1)) {
err = EINVAL;
return (err);
}
wi->format = (wi->id == VUIDMICE_VERTICAL_WHEEL_ID) ?
VUID_WHEEL_FORMAT_VERTICAL : VUID_WHEEL_FORMAT_HORIZONTAL;
return (err);
}
static int
vuidmice_service_wheel_state(register queue_t *qp,
register mblk_t *datap,
register uint_t cmd)
{
wheel_state *ws;
uint_t err = 0;
ws = (void *)datap->b_rptr;
if (ws->vers != VUID_WHEEL_STATE_VERS) {
err = EINVAL;
return (err);
}
if (ws->id > (VUIDMICE_NUM_WHEELS - 1)) {
err = EINVAL;
return (err);
}
switch (cmd) {
case VUIDGWHEELSTATE:
ws->stateflags =
(STATEP->wheel_state_bf >> ws->id) & 1;
break;
case VUIDSWHEELSTATE:
STATEP->wheel_state_bf = (ws->stateflags << ws->id) |
(STATEP->wheel_state_bf & ~(1 << ws->id));
break;
default:
err = EINVAL;
return (err);
}
return (err);
}
|