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