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