netbsd32_ioctl.c revision 1.96 1 /* $NetBSD: netbsd32_ioctl.c,v 1.96 2018/09/29 14:41:35 rmind Exp $ */
2
3 /*
4 * Copyright (c) 1998, 2001 Matthew R. Green
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 /*
30 * handle ioctl conversions from netbsd32 -> 64-bit kernel
31 */
32
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: netbsd32_ioctl.c,v 1.96 2018/09/29 14:41:35 rmind Exp $");
35
36 #if defined(_KERNEL_OPT)
37 #include "opt_ntp.h"
38 #endif
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/filedesc.h>
43 #include <sys/ioctl.h>
44 #include <sys/file.h>
45 #include <sys/proc.h>
46 #include <sys/socketvar.h>
47 #include <sys/audioio.h>
48 #include <sys/disklabel.h>
49 #include <sys/dkio.h>
50 #include <sys/ataio.h>
51 #include <sys/sockio.h>
52 #include <sys/socket.h>
53 #include <sys/ttycom.h>
54 #include <sys/mount.h>
55 #include <sys/syscallargs.h>
56 #include <sys/ktrace.h>
57 #include <sys/kmem.h>
58 #include <sys/envsys.h>
59 #include <sys/wdog.h>
60 #include <sys/clockctl.h>
61 #include <sys/exec_elf.h>
62 #include <sys/ksyms.h>
63 #include <sys/drvctlio.h>
64
65 #ifdef __sparc__
66 #include <dev/sun/fbio.h>
67 #include <machine/openpromio.h>
68 #endif
69
70 #include <net/if.h>
71 #include <net/route.h>
72
73 #include <net/if_pppoe.h>
74 #include <net/if_sppp.h>
75
76 #include <net/bpf.h>
77 #include <netinet/in.h>
78 #include <netinet/in_var.h>
79 #include <netinet/igmp.h>
80 #include <netinet/igmp_var.h>
81 #include <netinet/ip_mroute.h>
82
83 #include <compat/sys/sockio.h>
84
85 #include <compat/netbsd32/netbsd32.h>
86 #include <compat/netbsd32/netbsd32_ioctl.h>
87 #include <compat/netbsd32/netbsd32_syscallargs.h>
88 #include <compat/netbsd32/netbsd32_conv.h>
89
90 #include <dev/vndvar.h>
91
92 /* convert to/from different structures */
93
94 #if 0
95 static inline void
96 netbsd32_to_format_op(struct netbsd32_format_op *s32p, struct format_op *p, u_long cmd)
97 {
98
99 p->df_buf = (char *)NETBSD32PTR64(s32p->df_buf);
100 p->df_count = s32p->df_count;
101 p->df_startblk = s32p->df_startblk;
102 memcpy(p->df_reg, s32p->df_reg, sizeof(s32p->df_reg));
103 }
104 #endif
105
106 static inline void
107 netbsd32_to_ifreq(struct netbsd32_ifreq *s32p, struct ifreq *p, u_long cmd)
108 {
109
110 memcpy(p, s32p, sizeof *s32p);
111 /*
112 * XXX
113 * struct ifreq says the same, but sometimes the ifr_data
114 * union member needs to be converted to 64 bits... this
115 * is very driver specific and so we ignore it for now..
116 */
117 switch (cmd) {
118 case SIOCGIFDATA:
119 case SIOCZIFDATA:
120 case SIOCGIFGENERIC:
121 case SIOCSIFGENERIC:
122 p->ifr_data = (void *)NETBSD32PTR64(s32p->ifr_data);
123 break;
124 }
125 }
126
127 static inline void
128 netbsd32_to_oifreq(struct netbsd32_oifreq *s32p, struct oifreq *p, u_long cmd)
129 {
130
131 memcpy(p, s32p, sizeof *s32p);
132 /*
133 * XXX
134 * struct ifreq says the same, but sometimes the ifr_data
135 * union member needs to be converted to 64 bits... this
136 * is very driver specific and so we ignore it for now..
137 */
138 if (cmd == SIOCGIFDATA || cmd == SIOCZIFDATA)
139 p->ifr_data = (void *)NETBSD32PTR64(s32p->ifr_data);
140 }
141
142 static inline void
143 netbsd32_to_if_addrprefreq(const struct netbsd32_if_addrprefreq *ifap32,
144 struct if_addrprefreq *ifap, u_long cmd)
145 {
146 strlcpy(ifap->ifap_name, ifap32->ifap_name, sizeof(ifap->ifap_name));
147 ifap->ifap_preference = ifap32->ifap_preference;
148 memcpy(&ifap->ifap_addr, &ifap32->ifap_addr,
149 uimin(ifap32->ifap_addr.ss_len, _SS_MAXSIZE));
150 }
151
152 static inline void
153 netbsd32_to_ifconf(struct netbsd32_ifconf *s32p, struct ifconf *p, u_long cmd)
154 {
155
156 p->ifc_len = s32p->ifc_len;
157 /* ifc_buf & ifc_req are the same size so this works */
158 p->ifc_buf = (void *)NETBSD32PTR64(s32p->ifc_buf);
159 }
160
161 static inline void
162 netbsd32_to_ifmediareq(struct netbsd32_ifmediareq *s32p, struct ifmediareq *p, u_long cmd)
163 {
164
165 memcpy(p, s32p, sizeof *s32p);
166 p->ifm_ulist = (int *)NETBSD32PTR64(s32p->ifm_ulist);
167 }
168
169 static inline void
170 netbsd32_to_pppoediscparms(struct netbsd32_pppoediscparms *s32p,
171 struct pppoediscparms *p, u_long cmd)
172 {
173
174 memcpy(p->ifname, s32p->ifname, sizeof p->ifname);
175 memcpy(p->eth_ifname, s32p->eth_ifname, sizeof p->eth_ifname);
176 p->ac_name = (char *)NETBSD32PTR64(s32p->ac_name);
177 p->ac_name_len = s32p->ac_name_len;
178 p->service_name = (char *)NETBSD32PTR64(s32p->service_name);
179 p->service_name_len = s32p->service_name_len;
180 }
181
182 static inline void
183 netbsd32_to_spppauthcfg(struct netbsd32_spppauthcfg *s32p,
184 struct spppauthcfg *p, u_long cmd)
185 {
186
187 memcpy(p->ifname, s32p->ifname, sizeof p->ifname);
188 p->hisauth = s32p->hisauth;
189 p->myauth = s32p->myauth;
190 p->myname_length = s32p->myname_length;
191 p->mysecret_length = s32p->mysecret_length;
192 p->hisname_length = s32p->hisname_length;
193 p->hissecret_length = s32p->hissecret_length;
194 p->myauthflags = s32p->myauthflags;
195 p->hisauthflags = s32p->hisauthflags;
196 p->myname = (char *)NETBSD32PTR64(s32p->myname);
197 p->mysecret = (char *)NETBSD32PTR64(s32p->mysecret);
198 p->hisname = (char *)NETBSD32PTR64(s32p->hisname);
199 p->hissecret = (char *)NETBSD32PTR64(s32p->hissecret);
200 }
201
202 static inline void
203 netbsd32_to_ifdrv(struct netbsd32_ifdrv *s32p, struct ifdrv *p, u_long cmd)
204 {
205
206 memcpy(p->ifd_name, s32p->ifd_name, sizeof p->ifd_name);
207 p->ifd_cmd = s32p->ifd_cmd;
208 p->ifd_len = s32p->ifd_len;
209 p->ifd_data = (void *)NETBSD32PTR64(s32p->ifd_data);
210 }
211
212 static inline void
213 netbsd32_to_sioc_vif_req(struct netbsd32_sioc_vif_req *s32p, struct sioc_vif_req *p, u_long cmd)
214 {
215
216 p->vifi = s32p->vifi;
217 p->icount = (u_long)s32p->icount;
218 p->ocount = (u_long)s32p->ocount;
219 p->ibytes = (u_long)s32p->ibytes;
220 p->obytes = (u_long)s32p->obytes;
221 }
222
223 static inline void
224 netbsd32_to_sioc_sg_req(struct netbsd32_sioc_sg_req *s32p, struct sioc_sg_req *p, u_long cmd)
225 {
226
227 p->src = s32p->src;
228 p->grp = s32p->grp;
229 p->pktcnt = (u_long)s32p->pktcnt;
230 p->bytecnt = (u_long)s32p->bytecnt;
231 p->wrong_if = (u_long)s32p->wrong_if;
232 }
233
234 static inline void
235 netbsd32_to_atareq(struct netbsd32_atareq *s32p, struct atareq *p, u_long cmd)
236 {
237 p->flags = (u_long)s32p->flags;
238 p->command = s32p->command;
239 p->features = s32p->features;
240 p->sec_count = s32p->sec_count;
241 p->sec_num = s32p->sec_num;
242 p->head = s32p->head;
243 p->cylinder = s32p->cylinder;
244 p->databuf = (char *)NETBSD32PTR64(s32p->databuf);
245 p->datalen = (u_long)s32p->datalen;
246 p->timeout = s32p->timeout;
247 p->retsts = s32p->retsts;
248 p->error = s32p->error;
249 }
250
251 static inline void
252 netbsd32_to_vnd_ioctl(struct netbsd32_vnd_ioctl *s32p, struct vnd_ioctl *p, u_long cmd)
253 {
254
255 p->vnd_file = (char *)NETBSD32PTR64(s32p->vnd_file);
256 p->vnd_flags = s32p->vnd_flags;
257 p->vnd_geom = s32p->vnd_geom;
258 p->vnd_osize = s32p->vnd_osize;
259 p->vnd_size = s32p->vnd_size;
260 }
261
262 static inline void
263 netbsd32_to_vnd_user(struct netbsd32_vnd_user *s32p, struct vnd_user *p, u_long cmd)
264 {
265
266 p->vnu_unit = s32p->vnu_unit;
267 p->vnu_dev = s32p->vnu_dev;
268 p->vnu_ino = s32p->vnu_ino;
269 }
270
271 static inline void
272 netbsd32_to_vnd_ioctl50(struct netbsd32_vnd_ioctl50 *s32p, struct vnd_ioctl50 *p, u_long cmd)
273 {
274
275 p->vnd_file = (char *)NETBSD32PTR64(s32p->vnd_file);
276 p->vnd_flags = s32p->vnd_flags;
277 p->vnd_geom = s32p->vnd_geom;
278 p->vnd_size = s32p->vnd_size;
279 }
280
281 static inline void
282 netbsd32_to_plistref(struct netbsd32_plistref *s32p, struct plistref *p, u_long cmd)
283 {
284
285 p->pref_plist = NETBSD32PTR64(s32p->pref_plist);
286 p->pref_len = s32p->pref_len;
287 }
288
289 static inline void
290 netbsd32_to_u_long(netbsd32_u_long *s32p, u_long *p, u_long cmd)
291 {
292
293 *p = (u_long)*s32p;
294 }
295
296 static inline void
297 netbsd32_to_voidp(netbsd32_voidp *s32p, voidp *p, u_long cmd)
298 {
299
300 *p = (void *)NETBSD32PTR64(*s32p);
301 }
302
303 static inline void
304 netbsd32_to_wdog_conf(struct netbsd32_wdog_conf *s32p, struct wdog_conf *p, u_long cmd)
305 {
306
307 p->wc_names = (char *)NETBSD32PTR64(s32p->wc_names);
308 p->wc_count = s32p->wc_count;
309 }
310
311 static inline void
312 netbsd32_to_bpf_program(struct netbsd32_bpf_program *s32p, struct bpf_program *p, u_long cmd)
313 {
314
315 p->bf_insns = (void *)NETBSD32PTR64(s32p->bf_insns);
316 p->bf_len = s32p->bf_len;
317 }
318
319 static inline void
320 netbsd32_to_bpf_dltlist(struct netbsd32_bpf_dltlist *s32p, struct bpf_dltlist *p, u_long cmd)
321 {
322
323 p->bfl_list = (void *)NETBSD32PTR64(s32p->bfl_list);
324 p->bfl_len = s32p->bfl_len;
325 }
326
327 /* wsdisplay stuff */
328 static inline void
329 netbsd32_to_wsdisplay_addscreendata(struct netbsd32_wsdisplay_addscreendata *asd32,
330 struct wsdisplay_addscreendata *asd,
331 u_long cmd)
332 {
333 asd->screentype = (char *)NETBSD32PTR64(asd32->screentype);
334 asd->emul = (char *)NETBSD32PTR64(asd32->emul);
335 asd->idx = asd32->idx;
336 }
337
338 static inline void
339 netbsd32_to_ieee80211req(struct netbsd32_ieee80211req *ireq32,
340 struct ieee80211req *ireq, u_long cmd)
341 {
342 strlcpy(ireq->i_name, ireq32->i_name, IFNAMSIZ);
343 ireq->i_type = ireq32->i_type;
344 ireq->i_val = ireq32->i_val;
345 ireq->i_len = ireq32->i_len;
346 ireq->i_data = NETBSD32PTR64(ireq32->i_data);
347 }
348
349 static inline void
350 netbsd32_to_ieee80211_nwkey(struct netbsd32_ieee80211_nwkey *nwk32,
351 struct ieee80211_nwkey *nwk,
352 u_long cmd)
353 {
354 int i;
355
356 strlcpy(nwk->i_name, nwk32->i_name, IFNAMSIZ);
357 nwk->i_wepon = nwk32->i_wepon;
358 nwk->i_defkid = nwk32->i_defkid;
359 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
360 nwk->i_key[i].i_keylen = nwk32->i_key[i].i_keylen;
361 nwk->i_key[i].i_keydat =
362 NETBSD32PTR64(nwk32->i_key[i].i_keydat);
363 }
364 }
365
366 static inline void
367 netbsd32_to_wsdisplay_cursor(struct netbsd32_wsdisplay_cursor *c32,
368 struct wsdisplay_cursor *c,
369 u_long cmd)
370 {
371 c->which = c32->which;
372 c->enable = c32->enable;
373 c->pos.x = c32->pos.x;
374 c->pos.y = c32->pos.y;
375 c->hot.x = c32->hot.x;
376 c->hot.y = c32->hot.y;
377 c->size.x = c32->size.x;
378 c->size.y = c32->size.y;
379 c->cmap.index = c32->cmap.index;
380 c->cmap.count = c32->cmap.count;
381 c->cmap.red = NETBSD32PTR64(c32->cmap.red);
382 c->cmap.green = NETBSD32PTR64(c32->cmap.green);
383 c->cmap.blue = NETBSD32PTR64(c32->cmap.blue);
384 c->image = NETBSD32PTR64(c32->image);
385 c->mask = NETBSD32PTR64(c32->mask);
386 }
387
388 static inline void
389 netbsd32_to_wsdisplay_cmap(struct netbsd32_wsdisplay_cmap *c32,
390 struct wsdisplay_cmap *c,
391 u_long cmd)
392 {
393 c->index = c32->index;
394 c->count = c32->count;
395 c->red = NETBSD32PTR64(c32->red);
396 c->green = NETBSD32PTR64(c32->green);
397 c->blue = NETBSD32PTR64(c32->blue);
398 }
399
400 static inline void
401 netbsd32_to_wsdisplay_font(struct netbsd32_wsdisplay_font *f32,
402 struct wsdisplay_font *f,
403 u_long cmd)
404 {
405 f->name = NETBSD32PTR64(f32->name);
406 f->firstchar = f32->firstchar;
407 f->numchars = f32->numchars;
408 f->encoding = f32->encoding;
409 f->fontwidth = f32->fontwidth;
410 f->fontheight = f32->fontheight;
411 f->stride = f32->stride;
412 f->bitorder = f32->bitorder;
413 f->byteorder = f32->byteorder;
414 f->data = NETBSD32PTR64(f32->data);
415 }
416
417 static inline void
418 netbsd32_to_wsdisplay_usefontdata(struct netbsd32_wsdisplay_usefontdata *f32,
419 struct wsdisplay_usefontdata *f,
420 u_long cmd)
421 {
422 f->name = NETBSD32PTR64(f32->name);
423 }
424
425 static inline void
426 netbsd32_to_clockctl_settimeofday(
427 const struct netbsd32_clockctl_settimeofday *s32p,
428 struct clockctl_settimeofday *p,
429 u_long cmd)
430 {
431
432 p->tv = NETBSD32PTR64(s32p->tv);
433 p->tzp = NETBSD32PTR64(s32p->tzp);
434 }
435
436 static inline void
437 netbsd32_to_clockctl_adjtime(
438 const struct netbsd32_clockctl_adjtime *s32p,
439 struct clockctl_adjtime *p,
440 u_long cmd)
441 {
442
443 p->delta = NETBSD32PTR64(s32p->delta);
444 p->olddelta = NETBSD32PTR64(s32p->olddelta);
445 }
446
447 static inline void
448 netbsd32_to_clockctl_clock_settime(
449 const struct netbsd32_clockctl_clock_settime *s32p,
450 struct clockctl_clock_settime *p,
451 u_long cmd)
452 {
453
454 p->clock_id = s32p->clock_id;
455 p->tp = NETBSD32PTR64(s32p->tp);
456 }
457
458 #ifdef NTP
459 static inline void
460 netbsd32_to_clockctl_ntp_adjtime(
461 const struct netbsd32_clockctl_ntp_adjtime *s32p,
462 struct clockctl_ntp_adjtime *p,
463 u_long cmd)
464 {
465
466 p->tp = NETBSD32PTR64(s32p->tp);
467 p->retval = s32p->retval;
468 }
469 #endif
470
471 static inline void
472 netbsd32_to_ksyms_gsymbol(
473 const struct netbsd32_ksyms_gsymbol *s32p,
474 struct ksyms_gsymbol *p,
475 u_long cmd)
476 {
477
478 p->kg_name = NETBSD32PTR64(s32p->kg_name);
479 }
480
481 static inline void
482 netbsd32_to_ksyms_gvalue(
483 const struct netbsd32_ksyms_gvalue *s32p,
484 struct ksyms_gvalue *p,
485 u_long cmd)
486 {
487
488 p->kv_name = NETBSD32PTR64(s32p->kv_name);
489 }
490
491 static inline void
492 netbsd32_to_devlistargs(
493 const struct netbsd32_devlistargs *s32p,
494 struct devlistargs *p,
495 u_long cmd)
496 {
497 memcpy(p->l_devname, s32p->l_devname, sizeof(p->l_devname));
498 p->l_children = s32p->l_children;
499 p->l_childname = NETBSD32PTR64(s32p->l_childname);
500 }
501
502 static inline void
503 netbsd32_to_devrescanargs(
504 const struct netbsd32_devrescanargs *s32p,
505 struct devrescanargs *p,
506 u_long cmd)
507 {
508 memcpy(p->busname, s32p->busname, sizeof(p->busname));
509 memcpy(p->ifattr, s32p->ifattr, sizeof(p->ifattr));
510 p->numlocators = s32p->numlocators;
511 p->locators = NETBSD32PTR64(s32p->locators);
512 }
513
514 static inline void
515 netbsd32_to_disk_strategy(
516 const struct netbsd32_disk_strategy *s32p,
517 struct disk_strategy *p,
518 u_long cmd)
519 {
520 memcpy(p->dks_name, s32p->dks_name, sizeof(p->dks_name));
521 p->dks_param = NETBSD32PTR64(s32p->dks_param);
522 p->dks_paramlen = s32p->dks_paramlen;
523 }
524
525 static inline void
526 netbsd32_to_dkwedge_list(
527 const struct netbsd32_dkwedge_list *s32p,
528 struct dkwedge_list *p,
529 u_long cmd)
530 {
531 p->dkwl_buf = NETBSD32PTR64(s32p->dkwl_buf);
532 p->dkwl_bufsize = s32p->dkwl_bufsize;
533 p->dkwl_nwedges = s32p->dkwl_nwedges;
534 p->dkwl_ncopied = s32p->dkwl_ncopied;
535 }
536
537 /*
538 * handle ioctl conversions from 64-bit kernel -> netbsd32
539 */
540
541 #if 0
542 static inline void
543 netbsd32_from_format_op(struct format_op *p, struct netbsd32_format_op *s32p, u_long cmd)
544 {
545
546 /* filled in */
547 #if 0
548 s32p->df_buf = (netbsd32_charp)p->df_buf;
549 #endif
550 s32p->df_count = p->df_count;
551 s32p->df_startblk = p->df_startblk;
552 memcpy(s32p->df_reg, p->df_reg, sizeof(p->df_reg));
553 }
554 #endif
555
556 static inline void
557 netbsd32_from_ifreq(struct ifreq *p, struct netbsd32_ifreq *s32p, u_long cmd)
558 {
559
560 /*
561 * XXX
562 * struct ifreq says the same, but sometimes the ifr_data
563 * union member needs to be converted to 64 bits... this
564 * is very driver specific and so we ignore it for now..
565 */
566 memcpy(s32p, p, sizeof *s32p);
567 switch (cmd) {
568 case SIOCGIFDATA:
569 case SIOCZIFDATA:
570 case SIOCGIFGENERIC:
571 case SIOCSIFGENERIC:
572 NETBSD32PTR32(s32p->ifr_data, p->ifr_data);
573 break;
574 }
575 }
576
577 static inline void
578 netbsd32_from_oifreq(struct oifreq *p, struct netbsd32_oifreq *s32p, u_long cmd)
579 {
580
581 /*
582 * XXX
583 * struct ifreq says the same, but sometimes the ifr_data
584 * union member needs to be converted to 64 bits... this
585 * is very driver specific and so we ignore it for now..
586 */
587 memcpy(s32p, p, sizeof *s32p);
588 if (cmd == SIOCGIFDATA || cmd == SIOCZIFDATA)
589 NETBSD32PTR32(s32p->ifr_data, p->ifr_data);
590 }
591
592 static inline void
593 netbsd32_from_if_addrprefreq(const struct if_addrprefreq *ifap,
594 struct netbsd32_if_addrprefreq *ifap32, u_long cmd)
595 {
596 strlcpy(ifap32->ifap_name, ifap->ifap_name, sizeof(ifap32->ifap_name));
597 ifap32->ifap_preference = ifap->ifap_preference;
598 memcpy(&ifap32->ifap_addr, &ifap->ifap_addr,
599 uimin(ifap->ifap_addr.ss_len, _SS_MAXSIZE));
600 }
601
602 static inline void
603 netbsd32_from_ifconf(struct ifconf *p, struct netbsd32_ifconf *s32p, u_long cmd)
604 {
605
606 s32p->ifc_len = p->ifc_len;
607 /* ifc_buf & ifc_req are the same size so this works */
608 NETBSD32PTR32(s32p->ifc_buf, p->ifc_buf);
609 }
610
611 static inline void
612 netbsd32_from_ifmediareq(struct ifmediareq *p, struct netbsd32_ifmediareq *s32p, u_long cmd)
613 {
614
615 memcpy(s32p, p, sizeof *p);
616 /* filled in? */
617 #if 0
618 s32p->ifm_ulist = (netbsd32_intp_t)p->ifm_ulist;
619 #endif
620 }
621
622 static inline void
623 netbsd32_from_pppoediscparms(struct pppoediscparms *p,
624 struct netbsd32_pppoediscparms *s32p, u_long cmd)
625 {
626
627 memcpy(s32p->ifname, p->ifname, sizeof s32p->ifname);
628 memcpy(s32p->eth_ifname, p->eth_ifname, sizeof s32p->eth_ifname);
629 NETBSD32PTR32(s32p->ac_name, p->ac_name);
630 s32p->ac_name_len = p->ac_name_len;
631 NETBSD32PTR32(s32p->service_name, p->service_name);
632 s32p->service_name_len = p->service_name_len;
633 }
634
635 static inline void
636 netbsd32_from_spppauthcfg(struct spppauthcfg *p,
637 struct netbsd32_spppauthcfg *s32p, u_long cmd)
638 {
639
640 memcpy(s32p->ifname, p->ifname, sizeof s32p->ifname);
641 s32p->hisauth = p->hisauth;
642 s32p->myauth = p->myauth;
643 s32p->myname_length = p->myname_length;
644 s32p->mysecret_length = p->mysecret_length;
645 s32p->hisname_length = p->hisname_length;
646 s32p->hissecret_length = p->hissecret_length;
647 s32p->myauthflags = p->myauthflags;
648 s32p->hisauthflags = p->hisauthflags;
649 NETBSD32PTR32(s32p->myname, p->myname);
650 NETBSD32PTR32(s32p->mysecret, p->mysecret);
651 NETBSD32PTR32(s32p->hisname, p->hisname);
652 NETBSD32PTR32(s32p->hissecret, p->hissecret);
653 }
654
655 static inline void
656 netbsd32_from_ifdrv(struct ifdrv *p, struct netbsd32_ifdrv *s32p, u_long cmd)
657 {
658
659 memcpy(s32p->ifd_name, p->ifd_name, sizeof s32p->ifd_name);
660 s32p->ifd_cmd = p->ifd_cmd;
661 s32p->ifd_len = p->ifd_len;
662 NETBSD32PTR32(s32p->ifd_data, p->ifd_data);
663 }
664
665 static inline void
666 netbsd32_from_sioc_vif_req(struct sioc_vif_req *p, struct netbsd32_sioc_vif_req *s32p, u_long cmd)
667 {
668
669 s32p->vifi = p->vifi;
670 s32p->icount = (netbsd32_u_long)p->icount;
671 s32p->ocount = (netbsd32_u_long)p->ocount;
672 s32p->ibytes = (netbsd32_u_long)p->ibytes;
673 s32p->obytes = (netbsd32_u_long)p->obytes;
674 }
675
676 static inline void
677 netbsd32_from_sioc_sg_req(struct sioc_sg_req *p, struct netbsd32_sioc_sg_req *s32p, u_long cmd)
678 {
679
680 s32p->src = p->src;
681 s32p->grp = p->grp;
682 s32p->pktcnt = (netbsd32_u_long)p->pktcnt;
683 s32p->bytecnt = (netbsd32_u_long)p->bytecnt;
684 s32p->wrong_if = (netbsd32_u_long)p->wrong_if;
685 }
686
687 static inline void
688 netbsd32_from_atareq(struct atareq *p, struct netbsd32_atareq *s32p, u_long cmd)
689 {
690 s32p->flags = (netbsd32_u_long)p->flags;
691 s32p->command = p->command;
692 s32p->features = p->features;
693 s32p->sec_count = p->sec_count;
694 s32p->sec_num = p->sec_num;
695 s32p->head = p->head;
696 s32p->cylinder = p->cylinder;
697 NETBSD32PTR32(s32p->databuf, p->databuf);
698 s32p->datalen = (netbsd32_u_long)p->datalen;
699 s32p->timeout = p->timeout;
700 s32p->retsts = p->retsts;
701 s32p->error = p->error;
702 }
703
704 static inline void
705 netbsd32_from_vnd_ioctl(struct vnd_ioctl *p, struct netbsd32_vnd_ioctl *s32p, u_long cmd)
706 {
707
708 s32p->vnd_flags = p->vnd_flags;
709 s32p->vnd_geom = p->vnd_geom;
710 s32p->vnd_osize = p->vnd_osize;
711 s32p->vnd_size = p->vnd_size;
712 }
713
714 static inline void
715 netbsd32_from_vnd_user(struct vnd_user *p, struct netbsd32_vnd_user *s32p, u_long cmd)
716 {
717
718 s32p->vnu_unit = p->vnu_unit;
719 s32p->vnu_dev = p->vnu_dev;
720 s32p->vnu_ino = p->vnu_ino;
721 }
722
723 static inline void
724 netbsd32_from_vnd_ioctl50(struct vnd_ioctl50 *p, struct netbsd32_vnd_ioctl50 *s32p, u_long cmd)
725 {
726
727 s32p->vnd_flags = p->vnd_flags;
728 s32p->vnd_geom = p->vnd_geom;
729 s32p->vnd_size = p->vnd_size;
730 }
731
732 static inline void
733 netbsd32_from_plistref(struct plistref *p, struct netbsd32_plistref *s32p, u_long cmd)
734 {
735
736 NETBSD32PTR32(s32p->pref_plist, p->pref_plist);
737 s32p->pref_len = p->pref_len;
738 }
739
740 static inline void
741 netbsd32_from_wdog_conf(struct wdog_conf *p, struct netbsd32_wdog_conf *s32p, u_long cmd)
742 {
743
744 NETBSD32PTR32(s32p->wc_names, p->wc_names);
745 s32p->wc_count = p->wc_count;
746 }
747
748 /* wsdisplay stuff */
749 static inline void
750 netbsd32_from_wsdisplay_addscreendata(struct wsdisplay_addscreendata *asd,
751 struct netbsd32_wsdisplay_addscreendata *asd32,
752 u_long cmd)
753 {
754 NETBSD32PTR32(asd32->screentype, asd->screentype);
755 NETBSD32PTR32(asd32->emul, asd->emul);
756 asd32->idx = asd->idx;
757 }
758
759 static inline void
760 netbsd32_from_wsdisplay_cursor(struct wsdisplay_cursor *c,
761 struct netbsd32_wsdisplay_cursor *c32,
762 u_long cmd)
763 {
764 c32->which = c->which;
765 c32->enable = c->enable;
766 c32->pos.x = c->pos.x;
767 c32->pos.y = c->pos.y;
768 c32->hot.x = c->hot.x;
769 c32->hot.y = c->hot.y;
770 c32->size.x = c->size.x;
771 c32->size.y = c->size.y;
772 c32->cmap.index = c->cmap.index;
773 c32->cmap.count = c->cmap.count;
774 NETBSD32PTR32(c32->cmap.red, c->cmap.red);
775 NETBSD32PTR32(c32->cmap.green, c->cmap.green);
776 NETBSD32PTR32(c32->cmap.blue, c->cmap.blue);
777 NETBSD32PTR32(c32->image, c->image);
778 NETBSD32PTR32(c32->mask, c->mask);
779 }
780
781 static inline void
782 netbsd32_from_wsdisplay_cmap(struct wsdisplay_cmap *c,
783 struct netbsd32_wsdisplay_cmap *c32,
784 u_long cmd)
785 {
786 c32->index = c->index;
787 c32->count = c->count;
788 NETBSD32PTR32(c32->red, c->red);
789 NETBSD32PTR32(c32->green, c->green);
790 NETBSD32PTR32(c32->blue, c->blue);
791 }
792
793 static inline void
794 netbsd32_from_wsdisplay_font(struct wsdisplay_font *f,
795 struct netbsd32_wsdisplay_font *f32,
796 u_long cmd)
797 {
798 }
799
800 static inline void
801 netbsd32_from_wsdisplay_usefontdata(struct wsdisplay_usefontdata *f,
802 struct netbsd32_wsdisplay_usefontdata *f32,
803 u_long cmd)
804 {
805 }
806
807 static inline void
808 netbsd32_from_ieee80211req(struct ieee80211req *ireq,
809 struct netbsd32_ieee80211req *ireq32, u_long cmd)
810 {
811 strlcpy(ireq32->i_name, ireq->i_name, IFNAMSIZ);
812 ireq32->i_type = ireq->i_type;
813 ireq32->i_val = ireq->i_val;
814 ireq32->i_len = ireq->i_len;
815 NETBSD32PTR32(ireq32->i_data, ireq->i_data);
816 }
817
818 static inline void
819 netbsd32_from_ieee80211_nwkey(struct ieee80211_nwkey *nwk,
820 struct netbsd32_ieee80211_nwkey *nwk32,
821 u_long cmd)
822 {
823 int i;
824
825 strlcpy(nwk32->i_name, nwk->i_name, IFNAMSIZ);
826 nwk32->i_wepon = nwk->i_wepon;
827 nwk32->i_defkid = nwk->i_defkid;
828 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
829 nwk32->i_key[i].i_keylen = nwk->i_key[i].i_keylen;
830 NETBSD32PTR32(nwk32->i_key[i].i_keydat,
831 nwk->i_key[i].i_keydat);
832 }
833 }
834
835 static inline void
836 netbsd32_from_bpf_program(struct bpf_program *p, struct netbsd32_bpf_program *s32p, u_long cmd)
837 {
838
839 NETBSD32PTR32(s32p->bf_insns, p->bf_insns);
840 s32p->bf_len = p->bf_len;
841 }
842
843 static inline void
844 netbsd32_from_bpf_dltlist(struct bpf_dltlist *p, struct netbsd32_bpf_dltlist *s32p, u_long cmd)
845 {
846
847 NETBSD32PTR32(s32p->bfl_list, p->bfl_list);
848 s32p->bfl_len = p->bfl_len;
849 }
850
851 static inline void
852 netbsd32_from_u_long(u_long *p, netbsd32_u_long *s32p, u_long cmd)
853 {
854
855 *s32p = (netbsd32_u_long)*p;
856 }
857
858 static inline void
859 netbsd32_from_voidp(voidp *p, netbsd32_voidp *s32p, u_long cmd)
860 {
861
862 NETBSD32PTR32(*s32p, *p);
863 }
864
865
866 static inline void
867 netbsd32_from_clockctl_settimeofday(
868 const struct clockctl_settimeofday *p,
869 struct netbsd32_clockctl_settimeofday *s32p,
870 u_long cmd)
871 {
872
873 NETBSD32PTR32(s32p->tv, p->tv);
874 NETBSD32PTR32(s32p->tzp, p->tzp);
875 }
876
877 static inline void
878 netbsd32_from_clockctl_adjtime(
879 const struct clockctl_adjtime *p,
880 struct netbsd32_clockctl_adjtime *s32p,
881 u_long cmd)
882 {
883
884 NETBSD32PTR32(s32p->delta, p->delta);
885 NETBSD32PTR32(s32p->olddelta, p->olddelta);
886 }
887
888 static inline void
889 netbsd32_from_clockctl_clock_settime(
890 const struct clockctl_clock_settime *p,
891 struct netbsd32_clockctl_clock_settime *s32p,
892 u_long cmd)
893 {
894
895 s32p->clock_id = p->clock_id;
896 NETBSD32PTR32(s32p->tp, p->tp);
897 }
898
899 #ifdef NTP
900 static inline void
901 netbsd32_from_clockctl_ntp_adjtime(
902 const struct clockctl_ntp_adjtime *p,
903 struct netbsd32_clockctl_ntp_adjtime *s32p,
904 u_long cmd)
905 {
906
907 NETBSD32PTR32(s32p->tp, p->tp);
908 s32p->retval = p->retval;
909 }
910 #endif
911
912 static inline void
913 netbsd32_from_ksyms_gsymbol(
914 const struct ksyms_gsymbol *p,
915 struct netbsd32_ksyms_gsymbol *s32p,
916 u_long cmd)
917 {
918
919 NETBSD32PTR32(s32p->kg_name, p->kg_name);
920 s32p->kg_sym = p->kg_sym;
921 }
922
923 static inline void
924 netbsd32_from_ksyms_gvalue(
925 const struct ksyms_gvalue *p,
926 struct netbsd32_ksyms_gvalue *s32p,
927 u_long cmd)
928 {
929
930 NETBSD32PTR32(s32p->kv_name, p->kv_name);
931 s32p->kv_value = p->kv_value;
932 }
933
934 static inline void
935 netbsd32_from_devlistargs(
936 const struct devlistargs *p,
937 struct netbsd32_devlistargs *s32p,
938 u_long cmd)
939 {
940 memcpy(s32p->l_devname, p->l_devname, sizeof(s32p->l_devname));
941 s32p->l_children = p->l_children;
942 NETBSD32PTR32(s32p->l_childname, p->l_childname);
943 }
944
945 static inline void
946 netbsd32_from_devrescanargs(
947 const struct devrescanargs *p,
948 struct netbsd32_devrescanargs *s32p,
949 u_long cmd)
950 {
951 memcpy(s32p->busname, p->busname, sizeof(s32p->busname));
952 memcpy(s32p->ifattr, p->ifattr, sizeof(s32p->ifattr));
953 s32p->numlocators = p->numlocators;
954 NETBSD32PTR32(s32p->locators, p->locators);
955 }
956
957 static inline void
958 netbsd32_from_disk_strategy(
959 const struct disk_strategy *p,
960 struct netbsd32_disk_strategy *s32p,
961 u_long cmd)
962 {
963 memcpy(s32p->dks_name, p->dks_name, sizeof(p->dks_name));
964 NETBSD32PTR32(s32p->dks_param, p->dks_param);
965 s32p->dks_paramlen = p->dks_paramlen;
966 }
967
968 static inline void
969 netbsd32_from_dkwedge_list(
970 const struct dkwedge_list *p,
971 struct netbsd32_dkwedge_list *s32p,
972 u_long cmd)
973 {
974 NETBSD32PTR32(s32p->dkwl_buf, p->dkwl_buf);
975 s32p->dkwl_bufsize = p->dkwl_bufsize;
976 s32p->dkwl_nwedges = p->dkwl_nwedges;
977 s32p->dkwl_ncopied = p->dkwl_ncopied;
978 }
979
980 #ifdef NTP
981 static int
982 netbsd32_do_clockctl_ntp_adjtime(struct clockctl_ntp_adjtime *args)
983 {
984
985 struct netbsd32_timex ntv32;
986 struct timex ntv;
987 int error;
988
989 error = copyin(args->tp, &ntv32, sizeof(ntv32));
990 if (error)
991 return (error);
992
993 netbsd32_to_timex(&ntv32, &ntv);
994 ntp_adjtime1(&ntv);
995 netbsd32_from_timex(&ntv, &ntv32);
996
997 error = copyout(&ntv32, args->tp, sizeof(ntv));
998 if (error == 0)
999 args->retval = ntp_timestatus();
1000
1001 return error;
1002 }
1003 #endif
1004
1005 /*
1006 * main ioctl syscall.
1007 *
1008 * ok, here we are in the biggy. we have to do fix ups depending
1009 * on the ioctl command before and afterwards.
1010 */
1011 int
1012 netbsd32_ioctl(struct lwp *l, const struct netbsd32_ioctl_args *uap, register_t *retval)
1013 {
1014 /* {
1015 syscallarg(int) fd;
1016 syscallarg(netbsd32_u_long) com;
1017 syscallarg(netbsd32_voidp) data;
1018 } */
1019 struct proc *p = l->l_proc;
1020 struct file *fp;
1021 struct filedesc *fdp;
1022 u_long com;
1023 int error = 0;
1024 size_t size;
1025 size_t alloc_size32, size32;
1026 void *data, *memp = NULL;
1027 void *data32, *memp32 = NULL;
1028 unsigned int fd;
1029 fdfile_t *ff;
1030 int tmp;
1031 #define STK_PARAMS 128
1032 uint64_t stkbuf[STK_PARAMS/sizeof(uint64_t)];
1033 uint64_t stkbuf32[STK_PARAMS/sizeof(uint64_t)];
1034
1035 /*
1036 * we need to translate some commands (_IOW) before calling sys_ioctl,
1037 * some after (_IOR), and some both (_IOWR).
1038 */
1039 #if 0
1040 {
1041 const char * const dirs[8] = {
1042 "NONE!", "VOID", "OUT", "VOID|OUT!", "IN", "VOID|IN!",
1043 "INOUT", "VOID|IN|OUT!"
1044 };
1045
1046 printf("netbsd32_ioctl(%d, %x, %x): "
1047 "%s group %c base %d len %d\n",
1048 SCARG(uap, fd), SCARG(uap, com), SCARG(uap, data).i32,
1049 dirs[((SCARG(uap, com) & IOC_DIRMASK)>>29)],
1050 IOCGROUP(SCARG(uap, com)), IOCBASECMD(SCARG(uap, com)),
1051 IOCPARM_LEN(SCARG(uap, com)));
1052 }
1053 #endif
1054
1055 memp = NULL;
1056 memp32 = NULL;
1057 alloc_size32 = 0;
1058 size32 = 0;
1059 size = 0;
1060
1061 fdp = p->p_fd;
1062 fd = SCARG(uap, fd);
1063 if ((fp = fd_getfile(fd)) == NULL)
1064 return (EBADF);
1065 if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
1066 error = EBADF;
1067 goto out;
1068 }
1069
1070 ff = fdp->fd_dt->dt_ff[SCARG(uap, fd)];
1071 switch (com = SCARG(uap, com)) {
1072 case FIOCLEX:
1073 ff->ff_exclose = true;
1074 fdp->fd_exclose = true;
1075 goto out;
1076
1077 case FIONCLEX:
1078 ff->ff_exclose = false;
1079 goto out;
1080 }
1081
1082 /*
1083 * Interpret high order word to find amount of data to be
1084 * copied to/from the user's address space.
1085 */
1086 size32 = IOCPARM_LEN(com);
1087 alloc_size32 = size32;
1088
1089 /*
1090 * The disklabel is now padded to a multiple of 8 bytes however the old
1091 * disklabel on 32bit platforms wasn't. This leaves a difference in
1092 * size of 4 bytes between the two but are otherwise identical.
1093 * To deal with this, we allocate enough space for the new disklabel
1094 * but only copyin/out the smaller amount.
1095 */
1096 if (IOCGROUP(com) == 'd') {
1097 u_long ncom = com ^ (DIOCGDINFO ^ DIOCGDINFO32);
1098 switch (ncom) {
1099 case DIOCGDINFO:
1100 case DIOCWDINFO:
1101 case DIOCSDINFO:
1102 case DIOCGDEFLABEL:
1103 com = ncom;
1104 if (IOCPARM_LEN(DIOCGDINFO32) < IOCPARM_LEN(DIOCGDINFO))
1105 alloc_size32 = IOCPARM_LEN(DIOCGDINFO);
1106 break;
1107 }
1108 }
1109 if (alloc_size32 > IOCPARM_MAX) {
1110 error = ENOTTY;
1111 goto out;
1112 }
1113 if (alloc_size32 > sizeof(stkbuf)) {
1114 memp32 = kmem_alloc(alloc_size32, KM_SLEEP);
1115 data32 = memp32;
1116 } else
1117 data32 = (void *)stkbuf32;
1118 if ((com >> IOCPARM_SHIFT) == 0) {
1119 /* UNIX-style ioctl. */
1120 data32 = SCARG_P32(uap, data);
1121 } else {
1122 if (com&IOC_IN) {
1123 if (size32) {
1124 error = copyin(SCARG_P32(uap, data), data32,
1125 size32);
1126 if (error) {
1127 goto out;
1128 }
1129 /*
1130 * The data between size and alloc_size has
1131 * not been overwritten. It shouldn't matter
1132 * but let's clear that anyway.
1133 */
1134 if (__predict_false(size32 < alloc_size32)) {
1135 memset((char *)data32+size32, 0,
1136 alloc_size32 - size32);
1137 }
1138 ktrgenio(fd, UIO_WRITE, SCARG_P32(uap, data),
1139 size32, 0);
1140 } else
1141 *(void **)data32 = SCARG_P32(uap, data);
1142 } else if ((com&IOC_OUT) && size32) {
1143 /*
1144 * Zero the buffer so the user always
1145 * gets back something deterministic.
1146 */
1147 memset(data32, 0, alloc_size32);
1148 } else if (com&IOC_VOID) {
1149 *(void **)data32 = SCARG_P32(uap, data);
1150 }
1151 }
1152
1153 /*
1154 * convert various structures, pointers, and other objects that
1155 * change size from 32 bit -> 64 bit, for all ioctl commands.
1156 */
1157 switch (SCARG(uap, com)) {
1158 case FIONBIO:
1159 mutex_enter(&fp->f_lock);
1160 if ((tmp = *(int *)data32) != 0)
1161 fp->f_flag |= FNONBLOCK;
1162 else
1163 fp->f_flag &= ~FNONBLOCK;
1164 mutex_exit(&fp->f_lock);
1165 error = (*fp->f_ops->fo_ioctl)(fp, FIONBIO, (void *)&tmp);
1166 break;
1167
1168 case FIOASYNC:
1169 mutex_enter(&fp->f_lock);
1170 if ((tmp = *(int *)data32) != 0)
1171 fp->f_flag |= FASYNC;
1172 else
1173 fp->f_flag &= ~FASYNC;
1174 mutex_exit(&fp->f_lock);
1175 error = (*fp->f_ops->fo_ioctl)(fp, FIOASYNC, (void *)&tmp);
1176 break;
1177
1178 case AUDIO_WSEEK32:
1179 IOCTL_CONV_TO(AUDIO_WSEEK, u_long);
1180
1181 #if 0 /* not implemented by anything */
1182 case DIOCRFORMAT32:
1183 IOCTL_STRUCT_CONV_TO(DIOCRFORMAT, format_op);
1184 case DIOCWFORMAT32:
1185 IOCTL_STRUCT_CONV_TO(DIOCWFORMAT, format_op);
1186 #endif
1187
1188 case ATAIOCCOMMAND32:
1189 IOCTL_STRUCT_CONV_TO(ATAIOCCOMMAND, atareq);
1190
1191 case SIOCIFGCLONERS32:
1192 {
1193 struct netbsd32_if_clonereq *req =
1194 (struct netbsd32_if_clonereq *)data32;
1195 char *buf = NETBSD32PTR64(req->ifcr_buffer);
1196
1197 error = if_clone_list(req->ifcr_count,
1198 buf, &req->ifcr_total);
1199 break;
1200 }
1201
1202 /*
1203 * only a few ifreq syscalls need conversion and those are
1204 * all driver specific... XXX
1205 */
1206 #if 0
1207 case SIOCGADDRROM3232:
1208 IOCTL_STRUCT_CONV_TO(SIOCGADDRROM32, ifreq);
1209 case SIOCGCHIPID32:
1210 IOCTL_STRUCT_CONV_TO(SIOCGCHIPID, ifreq);
1211 case SIOCSIFADDR32:
1212 IOCTL_STRUCT_CONV_TO(SIOCSIFADDR, ifreq);
1213 case OSIOCGIFADDR32:
1214 IOCTL_STRUCT_CONV_TO(OSIOCGIFADDR, ifreq);
1215 case SIOCGIFADDR32:
1216 IOCTL_STRUCT_CONV_TO(SIOCGIFADDR, ifreq);
1217 case SIOCSIFDSTADDR32:
1218 IOCTL_STRUCT_CONV_TO(SIOCSIFDSTADDR, ifreq);
1219 case OSIOCGIFDSTADDR32:
1220 IOCTL_STRUCT_CONV_TO(OSIOCGIFDSTADDR, ifreq);
1221 case SIOCGIFDSTADDR32:
1222 IOCTL_STRUCT_CONV_TO(SIOCGIFDSTADDR, ifreq);
1223 case OSIOCGIFBRDADDR32:
1224 IOCTL_STRUCT_CONV_TO(OSIOCGIFBRDADDR, ifreq);
1225 case SIOCGIFBRDADDR32:
1226 IOCTL_STRUCT_CONV_TO(SIOCGIFBRDADDR, ifreq);
1227 case SIOCSIFBRDADDR32:
1228 IOCTL_STRUCT_CONV_TO(SIOCSIFBRDADDR, ifreq);
1229 case OSIOCGIFNETMASK32:
1230 IOCTL_STRUCT_CONV_TO(OSIOCGIFNETMASK, ifreq);
1231 case SIOCGIFNETMASK32:
1232 IOCTL_STRUCT_CONV_TO(SIOCGIFNETMASK, ifreq);
1233 case SIOCSIFNETMASK32:
1234 IOCTL_STRUCT_CONV_TO(SIOCSIFNETMASK, ifreq);
1235 case SIOCGIFMETRIC32:
1236 IOCTL_STRUCT_CONV_TO(SIOCGIFMETRIC, ifreq);
1237 case SIOCSIFMETRIC32:
1238 IOCTL_STRUCT_CONV_TO(SIOCSIFMETRIC, ifreq);
1239 case SIOCDIFADDR32:
1240 IOCTL_STRUCT_CONV_TO(SIOCDIFADDR, ifreq);
1241 case SIOCADDMULTI32:
1242 IOCTL_STRUCT_CONV_TO(SIOCADDMULTI, ifreq);
1243 case SIOCDELMULTI32:
1244 IOCTL_STRUCT_CONV_TO(SIOCDELMULTI, ifreq);
1245 case SIOCSIFMEDIA32:
1246 IOCTL_STRUCT_CONV_TO(SIOCSIFMEDIA, ifreq);
1247 case SIOCSIFMTU32:
1248 IOCTL_STRUCT_CONV_TO(SIOCSIFMTU, ifreq);
1249 case SIOCGIFMTU32:
1250 IOCTL_STRUCT_CONV_TO(SIOCGIFMTU, ifreq);
1251 case BIOCGETIF32:
1252 IOCTL_STRUCT_CONV_TO(BIOCGETIF, ifreq);
1253 case BIOCSETIF32:
1254 IOCTL_STRUCT_CONV_TO(BIOCSETIF, ifreq);
1255 case SIOCPHASE132:
1256 IOCTL_STRUCT_CONV_TO(SIOCPHASE1, ifreq);
1257 case SIOCPHASE232:
1258 IOCTL_STRUCT_CONV_TO(SIOCPHASE2, ifreq);
1259 #endif
1260
1261 case OOSIOCGIFCONF32:
1262 IOCTL_STRUCT_CONV_TO(OOSIOCGIFCONF, ifconf);
1263 case OSIOCGIFCONF32:
1264 IOCTL_STRUCT_CONV_TO(OSIOCGIFCONF, ifconf);
1265 case SIOCGIFCONF32:
1266 IOCTL_STRUCT_CONV_TO(SIOCGIFCONF, ifconf);
1267
1268 case SIOCGIFFLAGS32:
1269 IOCTL_STRUCT_CONV_TO(SIOCGIFFLAGS, ifreq);
1270 case SIOCSIFFLAGS32:
1271 IOCTL_STRUCT_CONV_TO(SIOCSIFFLAGS, ifreq);
1272
1273 case SIOCGIFADDRPREF32:
1274 IOCTL_STRUCT_CONV_TO(SIOCGIFADDRPREF, if_addrprefreq);
1275 case SIOCSIFADDRPREF32:
1276 IOCTL_STRUCT_CONV_TO(SIOCSIFADDRPREF, if_addrprefreq);
1277
1278
1279 case OSIOCGIFFLAGS32:
1280 IOCTL_STRUCT_CONV_TO(OSIOCGIFFLAGS, oifreq);
1281 case OSIOCSIFFLAGS32:
1282 IOCTL_STRUCT_CONV_TO(OSIOCSIFFLAGS, oifreq);
1283
1284 case SIOCGIFMEDIA32:
1285 IOCTL_STRUCT_CONV_TO(SIOCGIFMEDIA, ifmediareq);
1286
1287 case SIOCGIFGENERIC32:
1288 IOCTL_STRUCT_CONV_TO(SIOCGIFGENERIC, ifreq);
1289 case SIOCSIFGENERIC32:
1290 IOCTL_STRUCT_CONV_TO(SIOCSIFGENERIC, ifreq);
1291
1292 case PPPOESETPARMS32:
1293 IOCTL_STRUCT_CONV_TO(PPPOESETPARMS, pppoediscparms);
1294 case PPPOEGETPARMS32:
1295 IOCTL_STRUCT_CONV_TO(PPPOEGETPARMS, pppoediscparms);
1296 case SPPPGETAUTHCFG32:
1297 IOCTL_STRUCT_CONV_TO(SPPPGETAUTHCFG, spppauthcfg);
1298 case SPPPSETAUTHCFG32:
1299 IOCTL_STRUCT_CONV_TO(SPPPSETAUTHCFG, spppauthcfg);
1300
1301 case SIOCSDRVSPEC32:
1302 IOCTL_STRUCT_CONV_TO(SIOCSDRVSPEC, ifdrv);
1303 case SIOCGDRVSPEC32:
1304 IOCTL_STRUCT_CONV_TO(SIOCGDRVSPEC, ifdrv);
1305
1306 case SIOCGETVIFCNT32:
1307 IOCTL_STRUCT_CONV_TO(SIOCGETVIFCNT, sioc_vif_req);
1308
1309 case SIOCGETSGCNT32:
1310 IOCTL_STRUCT_CONV_TO(SIOCGETSGCNT, sioc_sg_req);
1311
1312 case VNDIOCSET32:
1313 IOCTL_STRUCT_CONV_TO(VNDIOCSET, vnd_ioctl);
1314
1315 case VNDIOCCLR32:
1316 IOCTL_STRUCT_CONV_TO(VNDIOCCLR, vnd_ioctl);
1317
1318 case VNDIOCGET32:
1319 IOCTL_STRUCT_CONV_TO(VNDIOCGET, vnd_user);
1320
1321 case VNDIOCSET5032:
1322 IOCTL_STRUCT_CONV_TO(VNDIOCSET50, vnd_ioctl50);
1323
1324 case VNDIOCCLR5032:
1325 IOCTL_STRUCT_CONV_TO(VNDIOCCLR50, vnd_ioctl50);
1326
1327 case ENVSYS_GETDICTIONARY32:
1328 IOCTL_STRUCT_CONV_TO(ENVSYS_GETDICTIONARY, plistref);
1329 case ENVSYS_SETDICTIONARY32:
1330 IOCTL_STRUCT_CONV_TO(ENVSYS_SETDICTIONARY, plistref);
1331 case ENVSYS_REMOVEPROPS32:
1332 IOCTL_STRUCT_CONV_TO(ENVSYS_REMOVEPROPS, plistref);
1333
1334 case WDOGIOC_GWDOGS32:
1335 IOCTL_STRUCT_CONV_TO(WDOGIOC_GWDOGS, wdog_conf);
1336
1337 case BIOCSETF32:
1338 IOCTL_STRUCT_CONV_TO(BIOCSETF, bpf_program);
1339 case BIOCSTCPF32:
1340 IOCTL_STRUCT_CONV_TO(BIOCSTCPF, bpf_program);
1341 case BIOCSUDPF32:
1342 IOCTL_STRUCT_CONV_TO(BIOCSUDPF, bpf_program);
1343 case BIOCGDLTLIST32:
1344 IOCTL_STRUCT_CONV_TO(BIOCGDLTLIST, bpf_dltlist);
1345
1346 case WSDISPLAYIO_ADDSCREEN32:
1347 IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_ADDSCREEN, wsdisplay_addscreendata);
1348
1349 case WSDISPLAYIO_GCURSOR32:
1350 IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_GCURSOR, wsdisplay_cursor);
1351 case WSDISPLAYIO_SCURSOR32:
1352 IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_SCURSOR, wsdisplay_cursor);
1353
1354 case WSDISPLAYIO_GETCMAP32:
1355 IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_GETCMAP, wsdisplay_cmap);
1356 case WSDISPLAYIO_PUTCMAP32:
1357 IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_PUTCMAP, wsdisplay_cmap);
1358
1359 case WSDISPLAYIO_LDFONT32:
1360 IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_LDFONT, wsdisplay_font);
1361 case WSDISPLAYIO_SFONT32:
1362 IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_SFONT, wsdisplay_usefontdata);
1363
1364 case SIOCS8021132:
1365 IOCTL_STRUCT_CONV_TO(SIOCS80211, ieee80211req);
1366 case SIOCG8021132:
1367 IOCTL_STRUCT_CONV_TO(SIOCG80211, ieee80211req);
1368 case SIOCS80211NWKEY32:
1369 IOCTL_STRUCT_CONV_TO(SIOCS80211NWKEY, ieee80211_nwkey);
1370 case SIOCG80211NWKEY32:
1371 IOCTL_STRUCT_CONV_TO(SIOCG80211NWKEY, ieee80211_nwkey);
1372
1373 case POWER_EVENT_RECVDICT32:
1374 IOCTL_STRUCT_CONV_TO(POWER_EVENT_RECVDICT, plistref);
1375
1376 case CLOCKCTL_SETTIMEOFDAY32:
1377 IOCTL_STRUCT_CONV_TO(CLOCKCTL_SETTIMEOFDAY,
1378 clockctl_settimeofday);
1379 case CLOCKCTL_ADJTIME32:
1380 IOCTL_STRUCT_CONV_TO(CLOCKCTL_ADJTIME, clockctl_adjtime);
1381 case CLOCKCTL_CLOCK_SETTIME32:
1382 IOCTL_STRUCT_CONV_TO(CLOCKCTL_CLOCK_SETTIME,
1383 clockctl_clock_settime);
1384 case CLOCKCTL_NTP_ADJTIME32:
1385 #ifdef NTP
1386 {
1387 size = IOCPARM_LEN(CLOCKCTL_NTP_ADJTIME);
1388 if (size > sizeof(stkbuf))
1389 data = memp = kmem_alloc(size, KM_SLEEP);
1390 else
1391 data = (void *)stkbuf;
1392
1393 netbsd32_to_clockctl_ntp_adjtime(
1394 (const struct netbsd32_clockctl_ntp_adjtime *)data32,
1395 (struct clockctl_ntp_adjtime *)data,
1396 CLOCKCTL_NTP_ADJTIME);
1397 error = netbsd32_do_clockctl_ntp_adjtime(
1398 (struct clockctl_ntp_adjtime *)data);
1399 netbsd32_from_clockctl_ntp_adjtime(
1400 (const struct clockctl_ntp_adjtime *)data,
1401 (struct netbsd32_clockctl_ntp_adjtime *)data32,
1402 CLOCKCTL_NTP_ADJTIME);
1403
1404 break;
1405 }
1406 #else
1407 error = ENOTTY;
1408 break;
1409 #endif /* NTP */
1410
1411 case KIOCGSYMBOL32:
1412 IOCTL_STRUCT_CONV_TO(KIOCGSYMBOL, ksyms_gsymbol);
1413 case KIOCGVALUE32:
1414 IOCTL_STRUCT_CONV_TO(KIOCGVALUE, ksyms_gvalue);
1415
1416 case DRVRESCANBUS32:
1417 IOCTL_STRUCT_CONV_TO(DRVRESCANBUS, devrescanargs);
1418 case DRVLISTDEV32:
1419 IOCTL_STRUCT_CONV_TO(DRVLISTDEV, devlistargs);
1420 case DRVCTLCOMMAND32:
1421 IOCTL_STRUCT_CONV_TO(DRVCTLCOMMAND, plistref);
1422 case DRVGETEVENT32:
1423 IOCTL_STRUCT_CONV_TO(DRVGETEVENT, plistref);
1424
1425 case DIOCGSTRATEGY32:
1426 IOCTL_STRUCT_CONV_TO(DIOCGSTRATEGY, disk_strategy);
1427 case DIOCSSTRATEGY32:
1428 IOCTL_STRUCT_CONV_TO(DIOCSSTRATEGY, disk_strategy);
1429 case DIOCLWEDGES32:
1430 IOCTL_STRUCT_CONV_TO(DIOCLWEDGES, dkwedge_list);
1431
1432 default:
1433 #ifdef NETBSD32_MD_IOCTL
1434 error = netbsd32_md_ioctl(fp, com, data32, l);
1435 #else
1436 error = (*fp->f_ops->fo_ioctl)(fp, com, data32);
1437 #endif
1438 break;
1439 }
1440
1441 if (error == EPASSTHROUGH)
1442 error = ENOTTY;
1443
1444 /*
1445 * Copy any data to user, size was
1446 * already set and checked above.
1447 */
1448 if (error == 0 && (com&IOC_OUT) && size32) {
1449 error = copyout(data32, SCARG_P32(uap, data), size32);
1450 ktrgenio(fd, UIO_READ, SCARG_P32(uap, data),
1451 size32, error);
1452 }
1453
1454 out:
1455 /* If we allocated data, free it here. */
1456 if (memp32)
1457 kmem_free(memp32, alloc_size32);
1458 if (memp)
1459 kmem_free(memp, size);
1460 fd_putfile(fd);
1461 return (error);
1462 }
1463