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