| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: wsbell.c,v 1.7 2017/06/13 00:54:37 nat Exp $ */ | | 1 | /* $NetBSD: wsbell.c,v 1.8 2017/06/13 05:49:48 nat Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2017 Nathanial Sloss <nathanialsloss@yahoo.com.au> | | 4 | * Copyright (c) 2017 Nathanial Sloss <nathanialsloss@yahoo.com.au> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Copyright (c) 2006 The NetBSD Foundation, Inc. | | 7 | * Copyright (c) 2006 The NetBSD Foundation, Inc. |
8 | * All rights reserved. | | 8 | * All rights reserved. |
9 | * | | 9 | * |
10 | * This code is derived from software contributed to The NetBSD Foundation | | 10 | * This code is derived from software contributed to The NetBSD Foundation |
11 | * by Julio M. Merino Vidal. | | 11 | * by Julio M. Merino Vidal. |
12 | * | | 12 | * |
13 | * Redistribution and use in source and binary forms, with or without | | 13 | * Redistribution and use in source and binary forms, with or without |
14 | * modification, are permitted provided that the following conditions | | 14 | * modification, are permitted provided that the following conditions |
| @@ -97,40 +97,41 @@ | | | @@ -97,40 +97,41 @@ |
97 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 97 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
98 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 98 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
99 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 99 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
100 | * SUCH DAMAGE. | | 100 | * SUCH DAMAGE. |
101 | * | | 101 | * |
102 | * @(#)ms.c 8.1 (Berkeley) 6/11/93 | | 102 | * @(#)ms.c 8.1 (Berkeley) 6/11/93 |
103 | */ | | 103 | */ |
104 | | | 104 | |
105 | /* | | 105 | /* |
106 | * Keyboard Bell driver. | | 106 | * Keyboard Bell driver. |
107 | */ | | 107 | */ |
108 | | | 108 | |
109 | #include <sys/cdefs.h> | | 109 | #include <sys/cdefs.h> |
110 | __KERNEL_RCSID(0, "$NetBSD: wsbell.c,v 1.7 2017/06/13 00:54:37 nat Exp $"); | | 110 | __KERNEL_RCSID(0, "$NetBSD: wsbell.c,v 1.8 2017/06/13 05:49:48 nat Exp $"); |
111 | | | 111 | |
112 | #if defined(_KERNEL_OPT) | | 112 | #if defined(_KERNEL_OPT) |
113 | #include "wsmux.h" | | 113 | #include "wsmux.h" |
114 | #endif | | 114 | #endif |
115 | | | 115 | |
116 | #include <sys/param.h> | | 116 | #include <sys/param.h> |
117 | #include <sys/conf.h> | | 117 | #include <sys/conf.h> |
118 | #include <sys/ioctl.h> | | 118 | #include <sys/ioctl.h> |
119 | #include <sys/poll.h> | | 119 | #include <sys/poll.h> |
120 | #include <sys/fcntl.h> | | 120 | #include <sys/fcntl.h> |
121 | #include <sys/kernel.h> | | 121 | #include <sys/kernel.h> |
122 | #include <sys/condvar.h> | | 122 | #include <sys/condvar.h> |
123 | #include <sys/mutex.h> | | 123 | #include <sys/mutex.h> |
| | | 124 | #include <sys/kauth.h> |
124 | #include <sys/kthread.h> | | 125 | #include <sys/kthread.h> |
125 | #include <sys/proc.h> | | 126 | #include <sys/proc.h> |
126 | #include <sys/syslog.h> | | 127 | #include <sys/syslog.h> |
127 | #include <sys/systm.h> | | 128 | #include <sys/systm.h> |
128 | #include <sys/tty.h> | | 129 | #include <sys/tty.h> |
129 | #include <sys/signalvar.h> | | 130 | #include <sys/signalvar.h> |
130 | #include <sys/device.h> | | 131 | #include <sys/device.h> |
131 | #include <sys/vnode.h> | | 132 | #include <sys/vnode.h> |
132 | #include <sys/callout.h> | | 133 | #include <sys/callout.h> |
133 | #include <sys/malloc.h> | | 134 | #include <sys/malloc.h> |
134 | #include <sys/module.h> | | 135 | #include <sys/module.h> |
135 | | | 136 | |
136 | #include <dev/wscons/wsconsio.h> | | 137 | #include <dev/wscons/wsconsio.h> |
| @@ -335,47 +336,64 @@ wsbelldoioctl(device_t dv, u_long cmd, v | | | @@ -335,47 +336,64 @@ wsbelldoioctl(device_t dv, u_long cmd, v |
335 | | | 336 | |
336 | sc->sc_refcnt++; | | 337 | sc->sc_refcnt++; |
337 | error = wsbell_do_ioctl(sc, cmd, data, flag, l); | | 338 | error = wsbell_do_ioctl(sc, cmd, data, flag, l); |
338 | if (--sc->sc_refcnt < 0) | | 339 | if (--sc->sc_refcnt < 0) |
339 | wakeup(sc); | | 340 | wakeup(sc); |
340 | return (error); | | 341 | return (error); |
341 | } | | 342 | } |
342 | | | 343 | |
343 | int | | 344 | int |
344 | wsbell_do_ioctl(struct wsbell_softc *sc, u_long cmd, void *data, | | 345 | wsbell_do_ioctl(struct wsbell_softc *sc, u_long cmd, void *data, |
345 | int flag, struct lwp *l) | | 346 | int flag, struct lwp *l) |
346 | { | | 347 | { |
347 | struct wskbd_bell_data *ubdp, *kbdp; | | 348 | struct wskbd_bell_data *ubdp, *kbdp; |
| | | 349 | int error; |
| | | 350 | |
348 | if (sc->sc_dying == true) | | 351 | if (sc->sc_dying == true) |
349 | return (EIO); | | 352 | return (EIO); |
350 | | | 353 | |
351 | /* | | 354 | /* |
352 | * Try the wsbell specific ioctls. | | 355 | * Try the wsbell specific ioctls. |
353 | */ | | 356 | */ |
354 | switch (cmd) { | | 357 | switch (cmd) { |
355 | case WSKBDIO_SETBELL: | | 358 | case WSKBDIO_SETBELL: |
356 | if ((flag & FWRITE) == 0) | | 359 | if ((flag & FWRITE) == 0) |
357 | return (EACCES); | | 360 | return (EACCES); |
358 | kbdp = &sc->sc_bell_data; | | 361 | kbdp = &sc->sc_bell_data; |
| | | 362 | setbell: |
359 | ubdp = (struct wskbd_bell_data *)data; | | 363 | ubdp = (struct wskbd_bell_data *)data; |
360 | SETBELL(kbdp, ubdp, kbdp); | | 364 | SETBELL(kbdp, ubdp, kbdp); |
361 | return (0); | | 365 | return (0); |
362 | | | 366 | |
363 | case WSKBDIO_GETBELL: | | 367 | case WSKBDIO_GETBELL: |
364 | kbdp = &sc->sc_bell_data; | | 368 | kbdp = &sc->sc_bell_data; |
| | | 369 | getbell: |
365 | ubdp = (struct wskbd_bell_data *)data; | | 370 | ubdp = (struct wskbd_bell_data *)data; |
366 | SETBELL(ubdp, kbdp, kbdp); | | 371 | SETBELL(ubdp, kbdp, kbdp); |
367 | return (0); | | 372 | return (0); |
368 | | | 373 | |
| | | 374 | case WSKBDIO_SETDEFAULTBELL: |
| | | 375 | if ((error = kauth_authorize_device(l->l_cred, |
| | | 376 | KAUTH_DEVICE_WSCONS_KEYBOARD_BELL, NULL, NULL, |
| | | 377 | NULL, NULL)) != 0) |
| | | 378 | return (error); |
| | | 379 | kbdp = &wskbd_default_bell_data; |
| | | 380 | goto setbell; |
| | | 381 | |
| | | 382 | |
| | | 383 | case WSKBDIO_GETDEFAULTBELL: |
| | | 384 | kbdp = &wskbd_default_bell_data; |
| | | 385 | goto getbell; |
| | | 386 | |
369 | case WSKBDIO_BELL: | | 387 | case WSKBDIO_BELL: |
370 | if ((flag & FWRITE) == 0) | | 388 | if ((flag & FWRITE) == 0) |
371 | return (EACCES); | | 389 | return (EACCES); |
372 | spkr_audio_play(sc, sc->sc_bell_data.pitch, | | 390 | spkr_audio_play(sc, sc->sc_bell_data.pitch, |
373 | sc->sc_bell_data.period, sc->sc_bell_data.volume); | | 391 | sc->sc_bell_data.period, sc->sc_bell_data.volume); |
374 | | | 392 | |
375 | return 0; | | 393 | return 0; |
376 | | | 394 | |
377 | case WSKBDIO_COMPLEXBELL: | | 395 | case WSKBDIO_COMPLEXBELL: |
378 | if ((flag & FWRITE) == 0) | | 396 | if ((flag & FWRITE) == 0) |
379 | return (EACCES); | | 397 | return (EACCES); |
380 | if (data == NULL) | | 398 | if (data == NULL) |
381 | return 0; | | 399 | return 0; |