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