The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/net80211/ieee80211_ioctl.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2001 Atsushi Onoe
    3  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
    4  * All rights reserved.
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions
    8  * are met:
    9  * 1. Redistributions of source code must retain the above copyright
   10  *    notice, this list of conditions and the following disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  * 3. The name of the author may not be used to endorse or promote products
   15  *    derived from this software without specific prior written permission.
   16  *
   17  * Alternatively, this software may be distributed under the terms of the
   18  * GNU General Public License ("GPL") version 2 as published by the Free
   19  * Software Foundation.
   20  *
   21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   31  */
   32 
   33 #include <sys/cdefs.h>
   34 __FBSDID("$FreeBSD: releng/6.1/sys/net80211/ieee80211_ioctl.c 157435 2006-04-03 17:21:05Z sam $");
   35 
   36 /*
   37  * IEEE 802.11 ioctl support (FreeBSD-specific)
   38  */
   39 
   40 #include "opt_inet.h"
   41 #include "opt_ipx.h"
   42 
   43 #include <sys/endian.h>
   44 #include <sys/param.h>
   45 #include <sys/kernel.h>
   46 #include <sys/socket.h>
   47 #include <sys/sockio.h>
   48 #include <sys/systm.h>
   49  
   50 #include <net/if.h>
   51 #include <net/if_arp.h>
   52 #include <net/if_media.h>
   53 #include <net/ethernet.h>
   54 
   55 #ifdef INET
   56 #include <netinet/in.h>
   57 #include <netinet/if_ether.h>
   58 #endif
   59 
   60 #ifdef IPX
   61 #include <netipx/ipx.h>
   62 #include <netipx/ipx_if.h>
   63 #endif
   64 
   65 #include <net80211/ieee80211_var.h>
   66 #include <net80211/ieee80211_ioctl.h>
   67 
   68 #include <dev/wi/if_wavelan_ieee.h>
   69 
   70 #define IS_UP(_ic) \
   71         (((_ic)->ic_ifp->if_flags & IFF_UP) &&                  \
   72             ((_ic)->ic_ifp->if_drv_flags & IFF_DRV_RUNNING))
   73 #define IS_UP_AUTO(_ic) \
   74         (IS_UP(_ic) && (_ic)->ic_roaming == IEEE80211_ROAMING_AUTO)
   75 
   76 /*
   77  * XXX
   78  * Wireless LAN specific configuration interface, which is compatible
   79  * with wicontrol(8).
   80  */
   81 
   82 struct wi_read_ap_args {
   83         int     i;              /* result count */
   84         struct wi_apinfo *ap;   /* current entry in result buffer */
   85         caddr_t max;            /* result buffer bound */
   86 };
   87 
   88 static void
   89 wi_read_ap_result(void *arg, struct ieee80211_node *ni)
   90 {
   91         struct ieee80211com *ic = ni->ni_ic;
   92         struct wi_read_ap_args *sa = arg;
   93         struct wi_apinfo *ap = sa->ap;
   94         struct ieee80211_rateset *rs;
   95         int j;
   96 
   97         if ((caddr_t)(ap + 1) > sa->max)
   98                 return;
   99         memset(ap, 0, sizeof(struct wi_apinfo));
  100         if (ic->ic_opmode == IEEE80211_M_HOSTAP) {
  101                 IEEE80211_ADDR_COPY(ap->bssid, ni->ni_macaddr);
  102                 ap->namelen = ic->ic_des_esslen;
  103                 if (ic->ic_des_esslen)
  104                         memcpy(ap->name, ic->ic_des_essid,
  105                             ic->ic_des_esslen);
  106         } else {
  107                 IEEE80211_ADDR_COPY(ap->bssid, ni->ni_bssid);
  108                 ap->namelen = ni->ni_esslen;
  109                 if (ni->ni_esslen)
  110                         memcpy(ap->name, ni->ni_essid,
  111                             ni->ni_esslen);
  112         }
  113         ap->channel = ieee80211_chan2ieee(ic, ni->ni_chan);
  114         ap->signal = ic->ic_node_getrssi(ni);
  115         ap->capinfo = ni->ni_capinfo;
  116         ap->interval = ni->ni_intval;
  117         rs = &ni->ni_rates;
  118         for (j = 0; j < rs->rs_nrates; j++) {
  119                 if (rs->rs_rates[j] & IEEE80211_RATE_BASIC) {
  120                         ap->rate = (rs->rs_rates[j] &
  121                             IEEE80211_RATE_VAL) * 5; /* XXX */
  122                 }
  123         }
  124         sa->i++;
  125         sa->ap++;
  126 }
  127 
  128 struct wi_read_prism2_args {
  129         int     i;              /* result count */
  130         struct wi_scan_res *res;/* current entry in result buffer */
  131         caddr_t max;            /* result buffer bound */
  132 };
  133 
  134 static void
  135 wi_read_prism2_result(void *arg, struct ieee80211_node *ni)
  136 {
  137         struct ieee80211com *ic = ni->ni_ic;
  138         struct wi_read_prism2_args *sa = arg;
  139         struct wi_scan_res *res = sa->res;
  140 
  141         if ((caddr_t)(res + 1) > sa->max)
  142                 return;
  143         res->wi_chan = ieee80211_chan2ieee(ic, ni->ni_chan);
  144         res->wi_noise = 0;
  145         res->wi_signal = ic->ic_node_getrssi(ni);
  146         IEEE80211_ADDR_COPY(res->wi_bssid, ni->ni_bssid);
  147         res->wi_interval = ni->ni_intval;
  148         res->wi_capinfo = ni->ni_capinfo;
  149         res->wi_ssid_len = ni->ni_esslen;
  150         memcpy(res->wi_ssid, ni->ni_essid, IEEE80211_NWID_LEN);
  151         /* NB: assumes wi_srates holds <= ni->ni_rates */
  152         memcpy(res->wi_srates, ni->ni_rates.rs_rates,
  153                 sizeof(res->wi_srates));
  154         if (ni->ni_rates.rs_nrates < 10)
  155                 res->wi_srates[ni->ni_rates.rs_nrates] = 0;
  156         res->wi_rate = ni->ni_rates.rs_rates[ni->ni_txrate];
  157         res->wi_rsvd = 0;
  158 
  159         sa->i++;
  160         sa->res++;
  161 }
  162 
  163 struct wi_read_sigcache_args {
  164         int     i;              /* result count */
  165         struct wi_sigcache *wsc;/* current entry in result buffer */
  166         caddr_t max;            /* result buffer bound */
  167 };
  168 
  169 static void
  170 wi_read_sigcache(void *arg, struct ieee80211_node *ni)
  171 {
  172         struct ieee80211com *ic = ni->ni_ic;
  173         struct wi_read_sigcache_args *sa = arg;
  174         struct wi_sigcache *wsc = sa->wsc;
  175 
  176         if ((caddr_t)(wsc + 1) > sa->max)
  177                 return;
  178         memset(wsc, 0, sizeof(struct wi_sigcache));
  179         IEEE80211_ADDR_COPY(wsc->macsrc, ni->ni_macaddr);
  180         wsc->signal = ic->ic_node_getrssi(ni);
  181 
  182         sa->wsc++;
  183         sa->i++;
  184 }
  185 
  186 int
  187 ieee80211_cfgget(struct ieee80211com *ic, u_long cmd, caddr_t data)
  188 {
  189         struct ifnet *ifp = ic->ic_ifp;
  190         int i, j, error;
  191         struct ifreq *ifr = (struct ifreq *)data;
  192         struct wi_req wreq;
  193         struct wi_ltv_keys *keys;
  194 
  195         error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
  196         if (error)
  197                 return error;
  198         wreq.wi_len = 0;
  199         switch (wreq.wi_type) {
  200         case WI_RID_SERIALNO:
  201                 /* nothing appropriate */
  202                 break;
  203         case WI_RID_NODENAME:
  204                 strcpy((char *)&wreq.wi_val[1], hostname);
  205                 wreq.wi_val[0] = htole16(strlen(hostname));
  206                 wreq.wi_len = (1 + strlen(hostname) + 1) / 2;
  207                 break;
  208         case WI_RID_CURRENT_SSID:
  209                 if (ic->ic_state != IEEE80211_S_RUN) {
  210                         wreq.wi_val[0] = 0;
  211                         wreq.wi_len = 1;
  212                         break;
  213                 }
  214                 wreq.wi_val[0] = htole16(ic->ic_bss->ni_esslen);
  215                 memcpy(&wreq.wi_val[1], ic->ic_bss->ni_essid,
  216                     ic->ic_bss->ni_esslen);
  217                 wreq.wi_len = (1 + ic->ic_bss->ni_esslen + 1) / 2;
  218                 break;
  219         case WI_RID_OWN_SSID:
  220         case WI_RID_DESIRED_SSID:
  221                 wreq.wi_val[0] = htole16(ic->ic_des_esslen);
  222                 memcpy(&wreq.wi_val[1], ic->ic_des_essid, ic->ic_des_esslen);
  223                 wreq.wi_len = (1 + ic->ic_des_esslen + 1) / 2;
  224                 break;
  225         case WI_RID_CURRENT_BSSID:
  226                 if (ic->ic_state == IEEE80211_S_RUN)
  227                         IEEE80211_ADDR_COPY(wreq.wi_val, ic->ic_bss->ni_bssid);
  228                 else
  229                         memset(wreq.wi_val, 0, IEEE80211_ADDR_LEN);
  230                 wreq.wi_len = IEEE80211_ADDR_LEN / 2;
  231                 break;
  232         case WI_RID_CHANNEL_LIST:
  233                 memset(wreq.wi_val, 0, sizeof(wreq.wi_val));
  234                 /*
  235                  * Since channel 0 is not available for DS, channel 1
  236                  * is assigned to LSB on WaveLAN.
  237                  */
  238                 if (ic->ic_phytype == IEEE80211_T_DS)
  239                         i = 1;
  240                 else
  241                         i = 0;
  242                 for (j = 0; i <= IEEE80211_CHAN_MAX; i++, j++)
  243                         if (isset(ic->ic_chan_active, i)) {
  244                                 setbit((u_int8_t *)wreq.wi_val, j);
  245                                 wreq.wi_len = j / 16 + 1;
  246                         }
  247                 break;
  248         case WI_RID_OWN_CHNL:
  249                 wreq.wi_val[0] = htole16(
  250                         ieee80211_chan2ieee(ic, ic->ic_ibss_chan));
  251                 wreq.wi_len = 1;
  252                 break;
  253         case WI_RID_CURRENT_CHAN:
  254                 wreq.wi_val[0] = htole16(
  255                         ieee80211_chan2ieee(ic, ic->ic_curchan));
  256                 wreq.wi_len = 1;
  257                 break;
  258         case WI_RID_COMMS_QUALITY:
  259                 wreq.wi_val[0] = 0;                             /* quality */
  260                 wreq.wi_val[1] = htole16(ic->ic_node_getrssi(ic->ic_bss));
  261                 wreq.wi_val[2] = 0;                             /* noise */
  262                 wreq.wi_len = 3;
  263                 break;
  264         case WI_RID_PROMISC:
  265                 wreq.wi_val[0] = htole16((ifp->if_flags & IFF_PROMISC) ? 1 : 0);
  266                 wreq.wi_len = 1;
  267                 break;
  268         case WI_RID_PORTTYPE:
  269                 wreq.wi_val[0] = htole16(ic->ic_opmode);
  270                 wreq.wi_len = 1;
  271                 break;
  272         case WI_RID_MAC_NODE:
  273                 IEEE80211_ADDR_COPY(wreq.wi_val, ic->ic_myaddr);
  274                 wreq.wi_len = IEEE80211_ADDR_LEN / 2;
  275                 break;
  276         case WI_RID_TX_RATE:
  277                 if (ic->ic_fixed_rate == IEEE80211_FIXED_RATE_NONE)
  278                         wreq.wi_val[0] = 0;     /* auto */
  279                 else
  280                         wreq.wi_val[0] = htole16(
  281                             (ic->ic_sup_rates[ic->ic_curmode].rs_rates[ic->ic_fixed_rate] &
  282                             IEEE80211_RATE_VAL) / 2);
  283                 wreq.wi_len = 1;
  284                 break;
  285         case WI_RID_CUR_TX_RATE:
  286                 wreq.wi_val[0] = htole16(
  287                     (ic->ic_bss->ni_rates.rs_rates[ic->ic_bss->ni_txrate] &
  288                     IEEE80211_RATE_VAL) / 2);
  289                 wreq.wi_len = 1;
  290                 break;
  291         case WI_RID_RTS_THRESH:
  292                 wreq.wi_val[0] = htole16(ic->ic_rtsthreshold);
  293                 wreq.wi_len = 1;
  294                 break;
  295         case WI_RID_CREATE_IBSS:
  296                 wreq.wi_val[0] =
  297                     htole16((ic->ic_flags & IEEE80211_F_IBSSON) ? 1 : 0);
  298                 wreq.wi_len = 1;
  299                 break;
  300         case WI_RID_MICROWAVE_OVEN:
  301                 wreq.wi_val[0] = 0;     /* no ... not supported */
  302                 wreq.wi_len = 1;
  303                 break;
  304         case WI_RID_ROAMING_MODE:
  305                 wreq.wi_val[0] = htole16(ic->ic_roaming);       /* XXX map */
  306                 wreq.wi_len = 1;
  307                 break;
  308         case WI_RID_SYSTEM_SCALE:
  309                 wreq.wi_val[0] = htole16(1);    /* low density ... not supp */
  310                 wreq.wi_len = 1;
  311                 break;
  312         case WI_RID_PM_ENABLED:
  313                 wreq.wi_val[0] =
  314                     htole16((ic->ic_flags & IEEE80211_F_PMGTON) ? 1 : 0);
  315                 wreq.wi_len = 1;
  316                 break;
  317         case WI_RID_MAX_SLEEP:
  318                 wreq.wi_val[0] = htole16(ic->ic_lintval);
  319                 wreq.wi_len = 1;
  320                 break;
  321         case WI_RID_CUR_BEACON_INT:
  322                 wreq.wi_val[0] = htole16(ic->ic_bss->ni_intval);
  323                 wreq.wi_len = 1;
  324                 break;
  325         case WI_RID_WEP_AVAIL:
  326                 wreq.wi_val[0] = htole16(1);    /* always available */
  327                 wreq.wi_len = 1;
  328                 break;
  329         case WI_RID_CNFAUTHMODE:
  330                 wreq.wi_val[0] = htole16(1);    /* TODO: open system only */
  331                 wreq.wi_len = 1;
  332                 break;
  333         case WI_RID_ENCRYPTION:
  334                 wreq.wi_val[0] =
  335                     htole16((ic->ic_flags & IEEE80211_F_PRIVACY) ? 1 : 0);
  336                 wreq.wi_len = 1;
  337                 break;
  338         case WI_RID_TX_CRYPT_KEY:
  339                 wreq.wi_val[0] = htole16(ic->ic_def_txkey);
  340                 wreq.wi_len = 1;
  341                 break;
  342         case WI_RID_DEFLT_CRYPT_KEYS:
  343                 keys = (struct wi_ltv_keys *)&wreq;
  344                 /* do not show keys to non-root user */
  345                 error = suser(curthread);
  346                 if (error) {
  347                         memset(keys, 0, sizeof(*keys));
  348                         error = 0;
  349                         break;
  350                 }
  351                 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
  352                         keys->wi_keys[i].wi_keylen =
  353                             htole16(ic->ic_nw_keys[i].wk_keylen);
  354                         memcpy(keys->wi_keys[i].wi_keydat,
  355                             ic->ic_nw_keys[i].wk_key,
  356                             ic->ic_nw_keys[i].wk_keylen);
  357                 }
  358                 wreq.wi_len = sizeof(*keys) / 2;
  359                 break;
  360         case WI_RID_MAX_DATALEN:
  361                 wreq.wi_val[0] = htole16(ic->ic_fragthreshold);
  362                 wreq.wi_len = 1;
  363                 break;
  364         case WI_RID_IFACE_STATS:
  365                 /* XXX: should be implemented in lower drivers */
  366                 break;
  367         case WI_RID_READ_APS:
  368                 /*
  369                  * Don't return results until active scan completes.
  370                  */
  371                 if ((ic->ic_flags & (IEEE80211_F_SCAN|IEEE80211_F_ASCAN)) == 0) {
  372                         struct wi_read_ap_args args;
  373 
  374                         args.i = 0;
  375                         args.ap = (void *)((char *)wreq.wi_val + sizeof(i));
  376                         args.max = (void *)(&wreq + 1);
  377                         ieee80211_iterate_nodes(&ic->ic_scan,
  378                                 wi_read_ap_result, &args);
  379                         memcpy(wreq.wi_val, &args.i, sizeof(args.i));
  380                         wreq.wi_len = (sizeof(int) +
  381                                 sizeof(struct wi_apinfo) * args.i) / 2;
  382                 } else
  383                         error = EINPROGRESS;
  384                 break;
  385         case WI_RID_PRISM2:
  386                 /* NB: we lie so WI_RID_SCAN_RES can include rates */
  387                 wreq.wi_val[0] = 1;
  388                 wreq.wi_len = sizeof(u_int16_t) / 2;
  389                 break;
  390         case WI_RID_SCAN_RES:                   /* compatibility interface */
  391                 if ((ic->ic_flags & (IEEE80211_F_SCAN|IEEE80211_F_ASCAN)) == 0) {
  392                         struct wi_read_prism2_args args;
  393                         struct wi_scan_p2_hdr *p2;
  394 
  395                         /* NB: use Prism2 format so we can include rate info */
  396                         p2 = (struct wi_scan_p2_hdr *)wreq.wi_val;
  397                         args.i = 0;
  398                         args.res = (void *)&p2[1];
  399                         args.max = (void *)(&wreq + 1);
  400                         ieee80211_iterate_nodes(&ic->ic_scan,
  401                                 wi_read_prism2_result, &args);
  402                         p2->wi_rsvd = 0;
  403                         p2->wi_reason = args.i;
  404                         wreq.wi_len = (sizeof(*p2) +
  405                                 sizeof(struct wi_scan_res) * args.i) / 2;
  406                 } else
  407                         error = EINPROGRESS;
  408                 break;
  409         case WI_RID_READ_CACHE: {
  410                 struct wi_read_sigcache_args args;
  411                 args.i = 0;
  412                 args.wsc = (struct wi_sigcache *) wreq.wi_val;
  413                 args.max = (void *)(&wreq + 1);
  414                 ieee80211_iterate_nodes(&ic->ic_scan, wi_read_sigcache, &args);
  415                 wreq.wi_len = sizeof(struct wi_sigcache) * args.i / 2;
  416                 break;
  417         }
  418         default:
  419                 error = EINVAL;
  420                 break;
  421         }
  422         if (error == 0) {
  423                 wreq.wi_len++;
  424                 error = copyout(&wreq, ifr->ifr_data, sizeof(wreq));
  425         }
  426         return error;
  427 }
  428 
  429 static int
  430 findrate(struct ieee80211com *ic, enum ieee80211_phymode mode, int rate)
  431 {
  432 #define IEEERATE(_ic,_m,_i) \
  433         ((_ic)->ic_sup_rates[_m].rs_rates[_i] & IEEE80211_RATE_VAL)
  434         int i, nrates = ic->ic_sup_rates[mode].rs_nrates;
  435         for (i = 0; i < nrates; i++)
  436                 if (IEEERATE(ic, mode, i) == rate)
  437                         return i;
  438         return -1;
  439 #undef IEEERATE
  440 }
  441 
  442 /*
  443  * Prepare to do a user-initiated scan for AP's.  If no
  444  * current/default channel is setup or the current channel
  445  * is invalid then pick the first available channel from
  446  * the active list as the place to start the scan.
  447  */
  448 static int
  449 ieee80211_setupscan(struct ieee80211com *ic, const u_int8_t chanlist[])
  450 {
  451 
  452         /*
  453          * XXX don't permit a scan to be started unless we
  454          * know the device is ready.  For the moment this means
  455          * the device is marked up as this is the required to
  456          * initialize the hardware.  It would be better to permit
  457          * scanning prior to being up but that'll require some
  458          * changes to the infrastructure.
  459          */
  460         if (!IS_UP(ic))
  461                 return EINVAL;
  462         memcpy(ic->ic_chan_active, chanlist, sizeof(ic->ic_chan_active));
  463         /*
  464          * We force the state to INIT before calling ieee80211_new_state
  465          * to get ieee80211_begin_scan called.  We really want to scan w/o
  466          * altering the current state but that's not possible right now.
  467          */
  468         /* XXX handle proberequest case */
  469         ic->ic_state = IEEE80211_S_INIT;        /* XXX bypass state machine */
  470         return 0;
  471 }
  472 
  473 int
  474 ieee80211_cfgset(struct ieee80211com *ic, u_long cmd, caddr_t data)
  475 {
  476         struct ifnet *ifp = ic->ic_ifp;
  477         int i, j, len, error, rate;
  478         struct ifreq *ifr = (struct ifreq *)data;
  479         struct wi_ltv_keys *keys;
  480         struct wi_req wreq;
  481         u_char chanlist[roundup(IEEE80211_CHAN_MAX, NBBY)];
  482 
  483         error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
  484         if (error)
  485                 return error;
  486         len = wreq.wi_len ? (wreq.wi_len - 1) * 2 : 0;
  487         switch (wreq.wi_type) {
  488         case WI_RID_SERIALNO:
  489         case WI_RID_NODENAME:
  490                 return EPERM;
  491         case WI_RID_CURRENT_SSID:
  492                 return EPERM;
  493         case WI_RID_OWN_SSID:
  494         case WI_RID_DESIRED_SSID:
  495                 if (le16toh(wreq.wi_val[0]) * 2 > len ||
  496                     le16toh(wreq.wi_val[0]) > IEEE80211_NWID_LEN) {
  497                         error = ENOSPC;
  498                         break;
  499                 }
  500                 memset(ic->ic_des_essid, 0, sizeof(ic->ic_des_essid));
  501                 ic->ic_des_esslen = le16toh(wreq.wi_val[0]) * 2;
  502                 memcpy(ic->ic_des_essid, &wreq.wi_val[1], ic->ic_des_esslen);
  503                 error = ENETRESET;
  504                 break;
  505         case WI_RID_CURRENT_BSSID:
  506                 return EPERM;
  507         case WI_RID_OWN_CHNL:
  508                 if (len != 2)
  509                         return EINVAL;
  510                 i = le16toh(wreq.wi_val[0]);
  511                 if (i < 0 ||
  512                     i > IEEE80211_CHAN_MAX ||
  513                     isclr(ic->ic_chan_active, i))
  514                         return EINVAL;
  515                 ic->ic_ibss_chan = &ic->ic_channels[i];
  516                 if (ic->ic_opmode == IEEE80211_M_MONITOR)
  517                         error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
  518                 else
  519                         error = ENETRESET;
  520                 break;
  521         case WI_RID_CURRENT_CHAN:
  522                 return EPERM;
  523         case WI_RID_COMMS_QUALITY:
  524                 return EPERM;
  525         case WI_RID_PROMISC:
  526                 if (len != 2)
  527                         return EINVAL;
  528                 if (ifp->if_flags & IFF_PROMISC) {
  529                         if (wreq.wi_val[0] == 0) {
  530                                 ifp->if_flags &= ~IFF_PROMISC;
  531                                 error = ENETRESET;
  532                         }
  533                 } else {
  534                         if (wreq.wi_val[0] != 0) {
  535                                 ifp->if_flags |= IFF_PROMISC;
  536                                 error = ENETRESET;
  537                         }
  538                 }
  539                 break;
  540         case WI_RID_PORTTYPE:
  541                 if (len != 2)
  542                         return EINVAL;
  543                 switch (le16toh(wreq.wi_val[0])) {
  544                 case IEEE80211_M_STA:
  545                         break;
  546                 case IEEE80211_M_IBSS:
  547                         if (!(ic->ic_caps & IEEE80211_C_IBSS))
  548                                 return EINVAL;
  549                         break;
  550                 case IEEE80211_M_AHDEMO:
  551                         if (ic->ic_phytype != IEEE80211_T_DS ||
  552                             !(ic->ic_caps & IEEE80211_C_AHDEMO))
  553                                 return EINVAL;
  554                         break;
  555                 case IEEE80211_M_HOSTAP:
  556                         if (!(ic->ic_caps & IEEE80211_C_HOSTAP))
  557                                 return EINVAL;
  558                         break;
  559                 default:
  560                         return EINVAL;
  561                 }
  562                 if (le16toh(wreq.wi_val[0]) != ic->ic_opmode) {
  563                         ic->ic_opmode = le16toh(wreq.wi_val[0]);
  564                         error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
  565                 }
  566                 break;
  567 #if 0
  568         case WI_RID_MAC_NODE:
  569                 if (len != IEEE80211_ADDR_LEN)
  570                         return EINVAL;
  571                 IEEE80211_ADDR_COPY(LLADDR(ifp->if_sadl), wreq.wi_val);
  572                 /* if_init will copy lladdr into ic_myaddr */
  573                 error = ENETRESET;
  574                 break;
  575 #endif
  576         case WI_RID_TX_RATE:
  577                 if (len != 2)
  578                         return EINVAL;
  579                 if (wreq.wi_val[0] == 0) {
  580                         /* auto */
  581                         ic->ic_fixed_rate = IEEE80211_FIXED_RATE_NONE;
  582                         break;
  583                 }
  584                 rate = 2 * le16toh(wreq.wi_val[0]);
  585                 if (ic->ic_curmode == IEEE80211_MODE_AUTO) {
  586                         /*
  587                          * In autoselect mode search for the rate.  We take
  588                          * the first instance which may not be right, but we
  589                          * are limited by the interface.  Note that we also
  590                          * lock the mode to insure the rate is meaningful
  591                          * when it is used.
  592                          */
  593                         for (j = IEEE80211_MODE_11A;
  594                              j < IEEE80211_MODE_MAX; j++) {
  595                                 if ((ic->ic_modecaps & (1<<j)) == 0)
  596                                         continue;
  597                                 i = findrate(ic, j, rate);
  598                                 if (i != -1) {
  599                                         /* lock mode too */
  600                                         ic->ic_curmode = j;
  601                                         goto setrate;
  602                                 }
  603                         }
  604                 } else {
  605                         i = findrate(ic, ic->ic_curmode, rate);
  606                         if (i != -1)
  607                                 goto setrate;
  608                 }
  609                 return EINVAL;
  610         setrate:
  611                 ic->ic_fixed_rate = i;
  612                 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
  613                 break;
  614         case WI_RID_CUR_TX_RATE:
  615                 return EPERM;
  616         case WI_RID_RTS_THRESH:
  617                 if (len != 2)
  618                         return EINVAL;
  619                 if (le16toh(wreq.wi_val[0]) != IEEE80211_MAX_LEN)
  620                         return EINVAL;          /* TODO: RTS */
  621                 break;
  622         case WI_RID_CREATE_IBSS:
  623                 if (len != 2)
  624                         return EINVAL;
  625                 if (wreq.wi_val[0] != 0) {
  626                         if ((ic->ic_caps & IEEE80211_C_IBSS) == 0)
  627                                 return EINVAL;
  628                         if ((ic->ic_flags & IEEE80211_F_IBSSON) == 0) {
  629                                 ic->ic_flags |= IEEE80211_F_IBSSON;
  630                                 if (ic->ic_opmode == IEEE80211_M_IBSS &&
  631                                     ic->ic_state == IEEE80211_S_SCAN)
  632                                         error = IS_UP_AUTO(ic) ? ENETRESET : 0;
  633                         }
  634                 } else {
  635                         if (ic->ic_flags & IEEE80211_F_IBSSON) {
  636                                 ic->ic_flags &= ~IEEE80211_F_IBSSON;
  637                                 if (ic->ic_flags & IEEE80211_F_SIBSS) {
  638                                         ic->ic_flags &= ~IEEE80211_F_SIBSS;
  639                                         error = IS_UP_AUTO(ic) ? ENETRESET : 0;
  640                                 }
  641                         }
  642                 }
  643                 break;
  644         case WI_RID_MICROWAVE_OVEN:
  645                 if (len != 2)
  646                         return EINVAL;
  647                 if (wreq.wi_val[0] != 0)
  648                         return EINVAL;          /* not supported */
  649                 break;
  650         case WI_RID_ROAMING_MODE:
  651                 if (len != 2)
  652                         return EINVAL;
  653                 i = le16toh(wreq.wi_val[0]);
  654                 if (i > IEEE80211_ROAMING_MANUAL)
  655                         return EINVAL;          /* not supported */
  656                 ic->ic_roaming = i;
  657                 break;
  658         case WI_RID_SYSTEM_SCALE:
  659                 if (len != 2)
  660                         return EINVAL;
  661                 if (le16toh(wreq.wi_val[0]) != 1)
  662                         return EINVAL;          /* not supported */
  663                 break;
  664         case WI_RID_PM_ENABLED:
  665                 if (len != 2)
  666                         return EINVAL;
  667                 if (wreq.wi_val[0] != 0) {
  668                         if ((ic->ic_caps & IEEE80211_C_PMGT) == 0)
  669                                 return EINVAL;
  670                         if ((ic->ic_flags & IEEE80211_F_PMGTON) == 0) {
  671                                 ic->ic_flags |= IEEE80211_F_PMGTON;
  672                                 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
  673                         }
  674                 } else {
  675                         if (ic->ic_flags & IEEE80211_F_PMGTON) {
  676                                 ic->ic_flags &= ~IEEE80211_F_PMGTON;
  677                                 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
  678                         }
  679                 }
  680                 break;
  681         case WI_RID_MAX_SLEEP:
  682                 if (len != 2)
  683                         return EINVAL;
  684                 ic->ic_lintval = le16toh(wreq.wi_val[0]);
  685                 if (ic->ic_flags & IEEE80211_F_PMGTON)
  686                         error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
  687                 break;
  688         case WI_RID_CUR_BEACON_INT:
  689                 return EPERM;
  690         case WI_RID_WEP_AVAIL:
  691                 return EPERM;
  692         case WI_RID_CNFAUTHMODE:
  693                 if (len != 2)
  694                         return EINVAL;
  695                 i = le16toh(wreq.wi_val[0]);
  696                 if (i > IEEE80211_AUTH_WPA)
  697                         return EINVAL;
  698                 ic->ic_bss->ni_authmode = i;            /* XXX ENETRESET? */
  699                 error = ENETRESET;
  700                 break;
  701         case WI_RID_ENCRYPTION:
  702                 if (len != 2)
  703                         return EINVAL;
  704                 if (wreq.wi_val[0] != 0) {
  705                         if ((ic->ic_caps & IEEE80211_C_WEP) == 0)
  706                                 return EINVAL;
  707                         if ((ic->ic_flags & IEEE80211_F_PRIVACY) == 0) {
  708                                 ic->ic_flags |= IEEE80211_F_PRIVACY;
  709                                 error = ENETRESET;
  710                         }
  711                 } else {
  712                         if (ic->ic_flags & IEEE80211_F_PRIVACY) {
  713                                 ic->ic_flags &= ~IEEE80211_F_PRIVACY;
  714                                 error = ENETRESET;
  715                         }
  716                 }
  717                 break;
  718         case WI_RID_TX_CRYPT_KEY:
  719                 if (len != 2)
  720                         return EINVAL;
  721                 i = le16toh(wreq.wi_val[0]);
  722                 if (i >= IEEE80211_WEP_NKID)
  723                         return EINVAL;
  724                 ic->ic_def_txkey = i;
  725                 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
  726                 break;
  727         case WI_RID_DEFLT_CRYPT_KEYS:
  728                 if (len != sizeof(struct wi_ltv_keys))
  729                         return EINVAL;
  730                 keys = (struct wi_ltv_keys *)&wreq;
  731                 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
  732                         len = le16toh(keys->wi_keys[i].wi_keylen);
  733                         if (len != 0 && len < IEEE80211_WEP_KEYLEN)
  734                                 return EINVAL;
  735                         if (len > IEEE80211_KEYBUF_SIZE)
  736                                 return EINVAL;
  737                 }
  738                 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
  739                         struct ieee80211_key *k = &ic->ic_nw_keys[i];
  740 
  741                         len = le16toh(keys->wi_keys[i].wi_keylen);
  742                         k->wk_keylen = len;
  743                         k->wk_flags = IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV;
  744                         memset(k->wk_key, 0, sizeof(k->wk_key));
  745                         memcpy(k->wk_key, keys->wi_keys[i].wi_keydat, len);
  746 #if 0
  747                         k->wk_type = IEEE80211_CIPHER_WEP;
  748 #endif
  749                 }
  750                 error = ENETRESET;
  751                 break;
  752         case WI_RID_MAX_DATALEN:
  753                 if (len != 2)
  754                         return EINVAL;
  755                 len = le16toh(wreq.wi_val[0]);
  756                 if (len < 350 /* ? */ || len > IEEE80211_MAX_LEN)
  757                         return EINVAL;
  758                 ic->ic_fragthreshold = len;
  759                 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
  760                 break;
  761         case WI_RID_IFACE_STATS:
  762                 error = EPERM;
  763                 break;
  764         case WI_RID_SCAN_REQ:                   /* XXX wicontrol */
  765                 if (ic->ic_opmode == IEEE80211_M_HOSTAP)
  766                         break;
  767                 error = ieee80211_setupscan(ic, ic->ic_chan_avail);
  768                 if (error == 0)
  769                         error = ieee80211_new_state(ic, IEEE80211_S_SCAN, -1);
  770                 break;
  771         case WI_RID_SCAN_APS:
  772                 if (ic->ic_opmode == IEEE80211_M_HOSTAP)
  773                         break;
  774                 len--;                  /* XXX: tx rate? */
  775                 /* FALLTHRU */
  776         case WI_RID_CHANNEL_LIST:
  777                 memset(chanlist, 0, sizeof(chanlist));
  778                 /*
  779                  * Since channel 0 is not available for DS, channel 1
  780                  * is assigned to LSB on WaveLAN.
  781                  */
  782                 if (ic->ic_phytype == IEEE80211_T_DS)
  783                         i = 1;
  784                 else
  785                         i = 0;
  786                 for (j = 0; i <= IEEE80211_CHAN_MAX; i++, j++) {
  787                         if ((j / 8) >= len)
  788                                 break;
  789                         if (isclr((u_int8_t *)wreq.wi_val, j))
  790                                 continue;
  791                         if (isclr(ic->ic_chan_active, i)) {
  792                                 if (wreq.wi_type != WI_RID_CHANNEL_LIST)
  793                                         continue;
  794                                 if (isclr(ic->ic_chan_avail, i))
  795                                         return EPERM;
  796                         }
  797                         setbit(chanlist, i);
  798                 }
  799                 error = ieee80211_setupscan(ic, chanlist);
  800                 if (wreq.wi_type == WI_RID_CHANNEL_LIST) {
  801                         /* NB: ignore error from ieee80211_setupscan */
  802                         error = ENETRESET;
  803                 } else if (error == 0)
  804                         error = ieee80211_new_state(ic, IEEE80211_S_SCAN, -1);
  805                 break;
  806         default:
  807                 error = EINVAL;
  808                 break;
  809         }
  810         if (error == ENETRESET && !IS_UP_AUTO(ic))
  811                 error = 0;
  812         return error;
  813 }
  814 
  815 static int
  816 cap2cipher(int flag)
  817 {
  818         switch (flag) {
  819         case IEEE80211_C_WEP:           return IEEE80211_CIPHER_WEP;
  820         case IEEE80211_C_AES:           return IEEE80211_CIPHER_AES_OCB;
  821         case IEEE80211_C_AES_CCM:       return IEEE80211_CIPHER_AES_CCM;
  822         case IEEE80211_C_CKIP:          return IEEE80211_CIPHER_CKIP;
  823         case IEEE80211_C_TKIP:          return IEEE80211_CIPHER_TKIP;
  824         }
  825         return -1;
  826 }
  827 
  828 static int
  829 ieee80211_ioctl_getkey(struct ieee80211com *ic, struct ieee80211req *ireq)
  830 {
  831         struct ieee80211_node *ni;
  832         struct ieee80211req_key ik;
  833         struct ieee80211_key *wk;
  834         const struct ieee80211_cipher *cip;
  835         u_int kid;
  836         int error;
  837 
  838         if (ireq->i_len != sizeof(ik))
  839                 return EINVAL;
  840         error = copyin(ireq->i_data, &ik, sizeof(ik));
  841         if (error)
  842                 return error;
  843         kid = ik.ik_keyix;
  844         if (kid == IEEE80211_KEYIX_NONE) {
  845                 ni = ieee80211_find_node(&ic->ic_sta, ik.ik_macaddr);
  846                 if (ni == NULL)
  847                         return EINVAL;          /* XXX */
  848                 wk = &ni->ni_ucastkey;
  849         } else {
  850                 if (kid >= IEEE80211_WEP_NKID)
  851                         return EINVAL;
  852                 wk = &ic->ic_nw_keys[kid];
  853                 IEEE80211_ADDR_COPY(&ik.ik_macaddr, ic->ic_bss->ni_macaddr);
  854                 ni = NULL;
  855         }
  856         cip = wk->wk_cipher;
  857         ik.ik_type = cip->ic_cipher;
  858         ik.ik_keylen = wk->wk_keylen;
  859         ik.ik_flags = wk->wk_flags & (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV);
  860         if (wk->wk_keyix == ic->ic_def_txkey)
  861                 ik.ik_flags |= IEEE80211_KEY_DEFAULT;
  862         if (suser(curthread) == 0) {
  863                 /* NB: only root can read key data */
  864                 ik.ik_keyrsc = wk->wk_keyrsc;
  865                 ik.ik_keytsc = wk->wk_keytsc;
  866                 memcpy(ik.ik_keydata, wk->wk_key, wk->wk_keylen);
  867                 if (cip->ic_cipher == IEEE80211_CIPHER_TKIP) {
  868                         memcpy(ik.ik_keydata+wk->wk_keylen,
  869                                 wk->wk_key + IEEE80211_KEYBUF_SIZE,
  870                                 IEEE80211_MICBUF_SIZE);
  871                         ik.ik_keylen += IEEE80211_MICBUF_SIZE;
  872                 }
  873         } else {
  874                 ik.ik_keyrsc = 0;
  875                 ik.ik_keytsc = 0;
  876                 memset(ik.ik_keydata, 0, sizeof(ik.ik_keydata));
  877         }
  878         if (ni != NULL)
  879                 ieee80211_free_node(ni);
  880         return copyout(&ik, ireq->i_data, sizeof(ik));
  881 }
  882 
  883 static int
  884 ieee80211_ioctl_getchanlist(struct ieee80211com *ic, struct ieee80211req *ireq)
  885 {
  886 
  887         if (sizeof(ic->ic_chan_active) < ireq->i_len)
  888                 ireq->i_len = sizeof(ic->ic_chan_active);
  889         return copyout(&ic->ic_chan_active, ireq->i_data, ireq->i_len);
  890 }
  891 
  892 static int
  893 ieee80211_ioctl_getchaninfo(struct ieee80211com *ic, struct ieee80211req *ireq)
  894 {
  895         struct ieee80211req_chaninfo chans;     /* XXX off stack? */
  896         int i, space;
  897 
  898         /*
  899          * Since channel 0 is not available for DS, channel 1
  900          * is assigned to LSB on WaveLAN.
  901          */
  902         if (ic->ic_phytype == IEEE80211_T_DS)
  903                 i = 1;
  904         else
  905                 i = 0;
  906         memset(&chans, 0, sizeof(chans));
  907         for (; i <= IEEE80211_CHAN_MAX; i++)
  908                 if (isset(ic->ic_chan_avail, i)) {
  909                         struct ieee80211_channel *c = &ic->ic_channels[i];
  910                         chans.ic_chans[chans.ic_nchans].ic_freq = c->ic_freq;
  911                         chans.ic_chans[chans.ic_nchans].ic_flags = c->ic_flags;
  912                         chans.ic_nchans++;
  913                 }
  914         space = __offsetof(struct ieee80211req_chaninfo,
  915                         ic_chans[chans.ic_nchans]);
  916         if (space > ireq->i_len)
  917                 space = ireq->i_len;
  918         return copyout(&chans, ireq->i_data, space);
  919 }
  920 
  921 static int
  922 ieee80211_ioctl_getwpaie(struct ieee80211com *ic, struct ieee80211req *ireq)
  923 {
  924         struct ieee80211_node *ni;
  925         struct ieee80211req_wpaie wpaie;
  926         int error;
  927 
  928         if (ireq->i_len < IEEE80211_ADDR_LEN)
  929                 return EINVAL;
  930         error = copyin(ireq->i_data, wpaie.wpa_macaddr, IEEE80211_ADDR_LEN);
  931         if (error != 0)
  932                 return error;
  933         ni = ieee80211_find_node(&ic->ic_sta, wpaie.wpa_macaddr);
  934         if (ni == NULL)
  935                 return EINVAL;          /* XXX */
  936         memset(wpaie.wpa_ie, 0, sizeof(wpaie.wpa_ie));
  937         if (ni->ni_wpa_ie != NULL) {
  938                 int ielen = ni->ni_wpa_ie[1] + 2;
  939                 if (ielen > sizeof(wpaie.wpa_ie))
  940                         ielen = sizeof(wpaie.wpa_ie);
  941                 memcpy(wpaie.wpa_ie, ni->ni_wpa_ie, ielen);
  942         }
  943         ieee80211_free_node(ni);
  944         if (ireq->i_len > sizeof(wpaie))
  945                 ireq->i_len = sizeof(wpaie);
  946         return copyout(&wpaie, ireq->i_data, ireq->i_len);
  947 }
  948 
  949 static int
  950 ieee80211_ioctl_getstastats(struct ieee80211com *ic, struct ieee80211req *ireq)
  951 {
  952         struct ieee80211_node *ni;
  953         u_int8_t macaddr[IEEE80211_ADDR_LEN];
  954         const int off = __offsetof(struct ieee80211req_sta_stats, is_stats);
  955         int error;
  956 
  957         if (ireq->i_len < off)
  958                 return EINVAL;
  959         error = copyin(ireq->i_data, macaddr, IEEE80211_ADDR_LEN);
  960         if (error != 0)
  961                 return error;
  962         ni = ieee80211_find_node(&ic->ic_sta, macaddr);
  963         if (ni == NULL)
  964                 return EINVAL;          /* XXX */
  965         if (ireq->i_len > sizeof(struct ieee80211req_sta_stats))
  966                 ireq->i_len = sizeof(struct ieee80211req_sta_stats);
  967         /* NB: copy out only the statistics */
  968         error = copyout(&ni->ni_stats, (u_int8_t *) ireq->i_data + off,
  969                         ireq->i_len - off);
  970         ieee80211_free_node(ni);
  971         return error;
  972 }
  973 
  974 static void
  975 get_scan_result(struct ieee80211req_scan_result *sr,
  976         const struct ieee80211_node *ni)
  977 {
  978         struct ieee80211com *ic = ni->ni_ic;
  979         u_int ielen = 0;
  980 
  981         memset(sr, 0, sizeof(*sr));
  982         sr->isr_ssid_len = ni->ni_esslen;
  983         if (ni->ni_wpa_ie != NULL)
  984                 ielen += 2+ni->ni_wpa_ie[1];
  985         if (ni->ni_wme_ie != NULL)
  986                 ielen += 2+ni->ni_wme_ie[1];
  987 
  988         /*
  989          * The value sr->isr_ie_len is defined as a uint8_t, so we
  990          * need to be careful to avoid an integer overflow.  If the
  991          * value would overflow, we will set isr_ie_len to zero, and
  992          * ieee80211_ioctl_getscanresults (below) will avoid copying
  993          * the (overflowing) data.
  994          */
  995         if (ielen > 255)
  996                 ielen = 0;
  997         sr->isr_ie_len = ielen;
  998         sr->isr_len = sizeof(*sr) + sr->isr_ssid_len + sr->isr_ie_len;
  999         sr->isr_len = roundup(sr->isr_len, sizeof(u_int32_t));
 1000         if (ni->ni_chan != IEEE80211_CHAN_ANYC) {
 1001                 sr->isr_freq = ni->ni_chan->ic_freq;
 1002                 sr->isr_flags = ni->ni_chan->ic_flags;
 1003         }
 1004         sr->isr_rssi = ic->ic_node_getrssi(ni);
 1005         sr->isr_intval = ni->ni_intval;
 1006         sr->isr_capinfo = ni->ni_capinfo;
 1007         sr->isr_erp = ni->ni_erp;
 1008         IEEE80211_ADDR_COPY(sr->isr_bssid, ni->ni_bssid);
 1009         sr->isr_nrates = ni->ni_rates.rs_nrates;
 1010         if (sr->isr_nrates > 15)
 1011                 sr->isr_nrates = 15;
 1012         memcpy(sr->isr_rates, ni->ni_rates.rs_rates, sr->isr_nrates);
 1013 }
 1014 
 1015 static int
 1016 ieee80211_ioctl_getscanresults(struct ieee80211com *ic, struct ieee80211req *ireq)
 1017 {
 1018         union {
 1019                 struct ieee80211req_scan_result res;
 1020                 char data[512];         /* XXX shrink? */
 1021         } u;
 1022         struct ieee80211req_scan_result *sr = &u.res;
 1023         struct ieee80211_node_table *nt;
 1024         struct ieee80211_node *ni;
 1025         int error, space;
 1026         u_int8_t *p, *cp;
 1027 
 1028         p = ireq->i_data;
 1029         space = ireq->i_len;
 1030         error = 0;
 1031         /* XXX locking */
 1032         nt =  &ic->ic_scan;
 1033         TAILQ_FOREACH(ni, &nt->nt_node, ni_list) {
 1034                 /* NB: skip pre-scan node state */ 
 1035                 if (ni->ni_chan == IEEE80211_CHAN_ANYC)
 1036                         continue;
 1037                 get_scan_result(sr, ni);
 1038                 if (sr->isr_len > sizeof(u))
 1039                         continue;               /* XXX */
 1040                 if (space < sr->isr_len)
 1041                         break;
 1042                 cp = (u_int8_t *)(sr+1);
 1043                 memcpy(cp, ni->ni_essid, ni->ni_esslen);
 1044                 cp += ni->ni_esslen;
 1045                 if (sr->isr_ie_len > 0 && ni->ni_wpa_ie != NULL) {
 1046                         memcpy(cp, ni->ni_wpa_ie, 2+ni->ni_wpa_ie[1]);
 1047                         cp += 2+ni->ni_wpa_ie[1];
 1048                 }
 1049                 if (sr->isr_ie_len > 0 && ni->ni_wme_ie != NULL) {
 1050                         memcpy(cp, ni->ni_wme_ie, 2+ni->ni_wme_ie[1]);
 1051                         cp += 2+ni->ni_wme_ie[1];
 1052                 }
 1053                 error = copyout(sr, p, sr->isr_len);
 1054                 if (error)
 1055                         break;
 1056                 p += sr->isr_len;
 1057                 space -= sr->isr_len;
 1058         }
 1059         ireq->i_len -= space;
 1060         return error;
 1061 }
 1062 
 1063 struct stainforeq {
 1064         struct ieee80211com *ic;
 1065         struct ieee80211req_sta_info *si;
 1066         size_t  space;
 1067 };
 1068 
 1069 static size_t
 1070 sta_space(const struct ieee80211_node *ni, size_t *ielen)
 1071 {
 1072         *ielen = 0;
 1073         if (ni->ni_wpa_ie != NULL)
 1074                 *ielen += 2+ni->ni_wpa_ie[1];
 1075         if (ni->ni_wme_ie != NULL)
 1076                 *ielen += 2+ni->ni_wme_ie[1];
 1077         return roundup(sizeof(struct ieee80211req_sta_info) + *ielen,
 1078                       sizeof(u_int32_t));
 1079 }
 1080 
 1081 static void
 1082 get_sta_space(void *arg, struct ieee80211_node *ni)
 1083 {
 1084         struct stainforeq *req = arg;
 1085         struct ieee80211com *ic = ni->ni_ic;
 1086         size_t ielen;
 1087 
 1088         if (ic->ic_opmode == IEEE80211_M_HOSTAP &&
 1089             ni->ni_associd == 0)        /* only associated stations */
 1090                 return;
 1091         req->space += sta_space(ni, &ielen);
 1092 }
 1093 
 1094 static void
 1095 get_sta_info(void *arg, struct ieee80211_node *ni)
 1096 {
 1097         struct stainforeq *req = arg;
 1098         struct ieee80211com *ic = ni->ni_ic;
 1099         struct ieee80211req_sta_info *si;
 1100         size_t ielen, len;
 1101         u_int8_t *cp;
 1102 
 1103         if (ic->ic_opmode == IEEE80211_M_HOSTAP &&
 1104             ni->ni_associd == 0)        /* only associated stations */
 1105                 return;
 1106         if (ni->ni_chan == IEEE80211_CHAN_ANYC) /* XXX bogus entry */
 1107                 return;
 1108         len = sta_space(ni, &ielen);
 1109         if (len > req->space)
 1110                 return;
 1111         si = req->si;
 1112         si->isi_len = len;
 1113         si->isi_ie_len = ielen;
 1114         si->isi_freq = ni->ni_chan->ic_freq;
 1115         si->isi_flags = ni->ni_chan->ic_flags;
 1116         si->isi_state = ni->ni_flags;
 1117         si->isi_authmode = ni->ni_authmode;
 1118         si->isi_rssi = ic->ic_node_getrssi(ni);
 1119         si->isi_capinfo = ni->ni_capinfo;
 1120         si->isi_erp = ni->ni_erp;
 1121         IEEE80211_ADDR_COPY(si->isi_macaddr, ni->ni_macaddr);
 1122         si->isi_nrates = ni->ni_rates.rs_nrates;
 1123         if (si->isi_nrates > 15)
 1124                 si->isi_nrates = 15;
 1125         memcpy(si->isi_rates, ni->ni_rates.rs_rates, si->isi_nrates);
 1126         si->isi_txrate = ni->ni_txrate;
 1127         si->isi_associd = ni->ni_associd;
 1128         si->isi_txpower = ni->ni_txpower;
 1129         si->isi_vlan = ni->ni_vlan;
 1130         if (ni->ni_flags & IEEE80211_NODE_QOS) {
 1131                 memcpy(si->isi_txseqs, ni->ni_txseqs, sizeof(ni->ni_txseqs));
 1132                 memcpy(si->isi_rxseqs, ni->ni_rxseqs, sizeof(ni->ni_rxseqs));
 1133         } else {
 1134                 si->isi_txseqs[0] = ni->ni_txseqs[0];
 1135                 si->isi_rxseqs[0] = ni->ni_rxseqs[0];
 1136         }
 1137         /* NB: leave all cases in case we relax ni_associd == 0 check */
 1138         if (ieee80211_node_is_authorized(ni))
 1139                 si->isi_inact = ic->ic_inact_run;
 1140         else if (ni->ni_associd != 0)
 1141                 si->isi_inact = ic->ic_inact_auth;
 1142         else
 1143                 si->isi_inact = ic->ic_inact_init;
 1144         si->isi_inact = (si->isi_inact - ni->ni_inact) * IEEE80211_INACT_WAIT;
 1145 
 1146         cp = (u_int8_t *)(si+1);
 1147         if (ni->ni_wpa_ie != NULL) {
 1148                 memcpy(cp, ni->ni_wpa_ie, 2+ni->ni_wpa_ie[1]);
 1149                 cp += 2+ni->ni_wpa_ie[1];
 1150         }
 1151         if (ni->ni_wme_ie != NULL) {
 1152                 memcpy(cp, ni->ni_wme_ie, 2+ni->ni_wme_ie[1]);
 1153                 cp += 2+ni->ni_wme_ie[1];
 1154         }
 1155 
 1156         req->si = (struct ieee80211req_sta_info *)(((u_int8_t *)si) + len);
 1157         req->space -= len;
 1158 }
 1159 
 1160 static int
 1161 ieee80211_ioctl_getstainfo(struct ieee80211com *ic, struct ieee80211req *ireq)
 1162 {
 1163         struct stainforeq req;
 1164         int error;
 1165 
 1166         if (ireq->i_len < sizeof(struct stainforeq))
 1167                 return EFAULT;
 1168 
 1169         error = 0;
 1170         req.space = 0;
 1171         ieee80211_iterate_nodes(&ic->ic_sta, get_sta_space, &req);
 1172         if (req.space > ireq->i_len)
 1173                 req.space = ireq->i_len;
 1174         if (req.space > 0) {
 1175                 size_t space;
 1176                 void *p;
 1177 
 1178                 space = req.space;
 1179                 /* XXX M_WAITOK after driver lock released */
 1180                 MALLOC(p, void *, space, M_TEMP, M_NOWAIT);
 1181                 if (p == NULL)
 1182                         return ENOMEM;
 1183                 req.si = p;
 1184                 ieee80211_iterate_nodes(&ic->ic_sta, get_sta_info, &req);
 1185                 ireq->i_len = space - req.space;
 1186                 error = copyout(p, ireq->i_data, ireq->i_len);
 1187                 FREE(p, M_TEMP);
 1188         } else
 1189                 ireq->i_len = 0;
 1190 
 1191         return error;
 1192 }
 1193 
 1194 static int
 1195 ieee80211_ioctl_getstatxpow(struct ieee80211com *ic, struct ieee80211req *ireq)
 1196 {
 1197         struct ieee80211_node *ni;
 1198         struct ieee80211req_sta_txpow txpow;
 1199         int error;
 1200 
 1201         if (ireq->i_len != sizeof(txpow))
 1202                 return EINVAL;
 1203         error = copyin(ireq->i_data, &txpow, sizeof(txpow));
 1204         if (error != 0)
 1205                 return error;
 1206         ni = ieee80211_find_node(&ic->ic_sta, txpow.it_macaddr);
 1207         if (ni == NULL)
 1208                 return EINVAL;          /* XXX */
 1209         txpow.it_txpow = ni->ni_txpower;
 1210         error = copyout(&txpow, ireq->i_data, sizeof(txpow));
 1211         ieee80211_free_node(ni);
 1212         return error;
 1213 }
 1214 
 1215 static int
 1216 ieee80211_ioctl_getwmeparam(struct ieee80211com *ic, struct ieee80211req *ireq)
 1217 {
 1218         struct ieee80211_wme_state *wme = &ic->ic_wme;
 1219         struct wmeParams *wmep;
 1220         int ac;
 1221 
 1222         if ((ic->ic_caps & IEEE80211_C_WME) == 0)
 1223                 return EINVAL;
 1224 
 1225         ac = (ireq->i_len & IEEE80211_WMEPARAM_VAL);
 1226         if (ac >= WME_NUM_AC)
 1227                 ac = WME_AC_BE;
 1228         if (ireq->i_len & IEEE80211_WMEPARAM_BSS)
 1229                 wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[ac];
 1230         else
 1231                 wmep = &wme->wme_wmeChanParams.cap_wmeParams[ac];
 1232         switch (ireq->i_type) {
 1233         case IEEE80211_IOC_WME_CWMIN:           /* WME: CWmin */
 1234                 ireq->i_val = wmep->wmep_logcwmin;
 1235                 break;
 1236         case IEEE80211_IOC_WME_CWMAX:           /* WME: CWmax */
 1237                 ireq->i_val = wmep->wmep_logcwmax;
 1238                 break;
 1239         case IEEE80211_IOC_WME_AIFS:            /* WME: AIFS */
 1240                 ireq->i_val = wmep->wmep_aifsn;
 1241                 break;
 1242         case IEEE80211_IOC_WME_TXOPLIMIT:       /* WME: txops limit */
 1243                 ireq->i_val = wmep->wmep_txopLimit;
 1244                 break;
 1245         case IEEE80211_IOC_WME_ACM:             /* WME: ACM (bss only) */
 1246                 wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[ac];
 1247                 ireq->i_val = wmep->wmep_acm;
 1248                 break;
 1249         case IEEE80211_IOC_WME_ACKPOLICY:       /* WME: ACK policy (!bss only)*/
 1250                 wmep = &wme->wme_wmeChanParams.cap_wmeParams[ac];
 1251                 ireq->i_val = !wmep->wmep_noackPolicy;
 1252                 break;
 1253         }
 1254         return 0;
 1255 }
 1256 
 1257 static int
 1258 ieee80211_ioctl_getmaccmd(struct ieee80211com *ic, struct ieee80211req *ireq)
 1259 {
 1260         const struct ieee80211_aclator *acl = ic->ic_acl;
 1261 
 1262         return (acl == NULL ? EINVAL : acl->iac_getioctl(ic, ireq));
 1263 }
 1264 
 1265 /*
 1266  * When building the kernel with -O2 on the i386 architecture, gcc
 1267  * seems to want to inline this function into ieee80211_ioctl()
 1268  * (which is the only routine that calls it). When this happens,
 1269  * ieee80211_ioctl() ends up consuming an additional 2K of stack
 1270  * space. (Exactly why it needs so much is unclear.) The problem
 1271  * is that it's possible for ieee80211_ioctl() to invoke other
 1272  * routines (including driver init functions) which could then find
 1273  * themselves perilously close to exhausting the stack.
 1274  *
 1275  * To avoid this, we deliberately prevent gcc from inlining this
 1276  * routine. Another way to avoid this is to use less agressive
 1277  * optimization when compiling this file (i.e. -O instead of -O2)
 1278  * but special-casing the compilation of this one module in the
 1279  * build system would be awkward.
 1280  */
 1281 #ifdef __GNUC__
 1282 __attribute__ ((noinline))
 1283 #endif
 1284 static int
 1285 ieee80211_ioctl_get80211(struct ieee80211com *ic, u_long cmd, struct ieee80211req *ireq)
 1286 {
 1287         const struct ieee80211_rsnparms *rsn = &ic->ic_bss->ni_rsn;
 1288         int error = 0;
 1289         u_int kid, len, m;
 1290         u_int8_t tmpkey[IEEE80211_KEYBUF_SIZE];
 1291         char tmpssid[IEEE80211_NWID_LEN];
 1292 
 1293         switch (ireq->i_type) {
 1294         case IEEE80211_IOC_SSID:
 1295                 switch (ic->ic_state) {
 1296                 case IEEE80211_S_INIT:
 1297                 case IEEE80211_S_SCAN:
 1298                         ireq->i_len = ic->ic_des_esslen;
 1299                         memcpy(tmpssid, ic->ic_des_essid, ireq->i_len);
 1300                         break;
 1301                 default:
 1302                         ireq->i_len = ic->ic_bss->ni_esslen;
 1303                         memcpy(tmpssid, ic->ic_bss->ni_essid,
 1304                                 ireq->i_len);
 1305                         break;
 1306                 }
 1307                 error = copyout(tmpssid, ireq->i_data, ireq->i_len);
 1308                 break;
 1309         case IEEE80211_IOC_NUMSSIDS:
 1310                 ireq->i_val = 1;
 1311                 break;
 1312         case IEEE80211_IOC_WEP:
 1313                 if ((ic->ic_flags & IEEE80211_F_PRIVACY) == 0)
 1314                         ireq->i_val = IEEE80211_WEP_OFF;
 1315                 else if (ic->ic_flags & IEEE80211_F_DROPUNENC)
 1316                         ireq->i_val = IEEE80211_WEP_ON;
 1317                 else
 1318                         ireq->i_val = IEEE80211_WEP_MIXED;
 1319                 break;
 1320         case IEEE80211_IOC_WEPKEY:
 1321                 kid = (u_int) ireq->i_val;
 1322                 if (kid >= IEEE80211_WEP_NKID)
 1323                         return EINVAL;
 1324                 len = (u_int) ic->ic_nw_keys[kid].wk_keylen;
 1325                 /* NB: only root can read WEP keys */
 1326                 if (suser(curthread) == 0) {
 1327                         bcopy(ic->ic_nw_keys[kid].wk_key, tmpkey, len);
 1328                 } else {
 1329                         bzero(tmpkey, len);
 1330                 }
 1331                 ireq->i_len = len;
 1332                 error = copyout(tmpkey, ireq->i_data, len);
 1333                 break;
 1334         case IEEE80211_IOC_NUMWEPKEYS:
 1335                 ireq->i_val = IEEE80211_WEP_NKID;
 1336                 break;
 1337         case IEEE80211_IOC_WEPTXKEY:
 1338                 ireq->i_val = ic->ic_def_txkey;
 1339                 break;
 1340         case IEEE80211_IOC_AUTHMODE:
 1341                 if (ic->ic_flags & IEEE80211_F_WPA)
 1342                         ireq->i_val = IEEE80211_AUTH_WPA;
 1343                 else
 1344                         ireq->i_val = ic->ic_bss->ni_authmode;
 1345                 break;
 1346         case IEEE80211_IOC_CHANNEL:
 1347                 ireq->i_val = ieee80211_chan2ieee(ic, ic->ic_curchan);
 1348                 break;
 1349         case IEEE80211_IOC_POWERSAVE:
 1350                 if (ic->ic_flags & IEEE80211_F_PMGTON)
 1351                         ireq->i_val = IEEE80211_POWERSAVE_ON;
 1352                 else
 1353                         ireq->i_val = IEEE80211_POWERSAVE_OFF;
 1354                 break;
 1355         case IEEE80211_IOC_POWERSAVESLEEP:
 1356                 ireq->i_val = ic->ic_lintval;
 1357                 break;
 1358         case IEEE80211_IOC_RTSTHRESHOLD:
 1359                 ireq->i_val = ic->ic_rtsthreshold;
 1360                 break;
 1361         case IEEE80211_IOC_PROTMODE:
 1362                 ireq->i_val = ic->ic_protmode;
 1363                 break;
 1364         case IEEE80211_IOC_TXPOWER:
 1365                 if ((ic->ic_caps & IEEE80211_C_TXPMGT) == 0)
 1366                         return EINVAL;
 1367                 ireq->i_val = ic->ic_txpowlimit;
 1368                 break;
 1369         case IEEE80211_IOC_MCASTCIPHER:
 1370                 ireq->i_val = rsn->rsn_mcastcipher;
 1371                 break;
 1372         case IEEE80211_IOC_MCASTKEYLEN:
 1373                 ireq->i_val = rsn->rsn_mcastkeylen;
 1374                 break;
 1375         case IEEE80211_IOC_UCASTCIPHERS:
 1376                 ireq->i_val = 0;
 1377                 for (m = 0x1; m != 0; m <<= 1)
 1378                         if (rsn->rsn_ucastcipherset & m)
 1379                                 ireq->i_val |= 1<<cap2cipher(m);
 1380                 break;
 1381         case IEEE80211_IOC_UCASTCIPHER:
 1382                 ireq->i_val = rsn->rsn_ucastcipher;
 1383                 break;
 1384         case IEEE80211_IOC_UCASTKEYLEN:
 1385                 ireq->i_val = rsn->rsn_ucastkeylen;
 1386                 break;
 1387         case IEEE80211_IOC_KEYMGTALGS:
 1388                 ireq->i_val = rsn->rsn_keymgmtset;
 1389                 break;
 1390         case IEEE80211_IOC_RSNCAPS:
 1391                 ireq->i_val = rsn->rsn_caps;
 1392                 break;
 1393         case IEEE80211_IOC_WPA:
 1394                 switch (ic->ic_flags & IEEE80211_F_WPA) {
 1395                 case IEEE80211_F_WPA1:
 1396                         ireq->i_val = 1;
 1397                         break;
 1398                 case IEEE80211_F_WPA2:
 1399                         ireq->i_val = 2;
 1400                         break;
 1401                 case IEEE80211_F_WPA1 | IEEE80211_F_WPA2:
 1402                         ireq->i_val = 3;
 1403                         break;
 1404                 default:
 1405                         ireq->i_val = 0;
 1406                         break;
 1407                 }
 1408                 break;
 1409         case IEEE80211_IOC_CHANLIST:
 1410                 error = ieee80211_ioctl_getchanlist(ic, ireq);
 1411                 break;
 1412         case IEEE80211_IOC_ROAMING:
 1413                 ireq->i_val = ic->ic_roaming;
 1414                 break;
 1415         case IEEE80211_IOC_PRIVACY:
 1416                 ireq->i_val = (ic->ic_flags & IEEE80211_F_PRIVACY) != 0;
 1417                 break;
 1418         case IEEE80211_IOC_DROPUNENCRYPTED:
 1419                 ireq->i_val = (ic->ic_flags & IEEE80211_F_DROPUNENC) != 0;
 1420                 break;
 1421         case IEEE80211_IOC_COUNTERMEASURES:
 1422                 ireq->i_val = (ic->ic_flags & IEEE80211_F_COUNTERM) != 0;
 1423                 break;
 1424         case IEEE80211_IOC_DRIVER_CAPS:
 1425                 ireq->i_val = ic->ic_caps>>16;
 1426                 ireq->i_len = ic->ic_caps&0xffff;
 1427                 break;
 1428         case IEEE80211_IOC_WME:
 1429                 ireq->i_val = (ic->ic_flags & IEEE80211_F_WME) != 0;
 1430                 break;
 1431         case IEEE80211_IOC_HIDESSID:
 1432                 ireq->i_val = (ic->ic_flags & IEEE80211_F_HIDESSID) != 0;
 1433                 break;
 1434         case IEEE80211_IOC_APBRIDGE:
 1435                 ireq->i_val = (ic->ic_flags & IEEE80211_F_NOBRIDGE) == 0;
 1436                 break;
 1437         case IEEE80211_IOC_OPTIE:
 1438                 if (ic->ic_opt_ie == NULL)
 1439                         return EINVAL;
 1440                 /* NB: truncate, caller can check length */
 1441                 if (ireq->i_len > ic->ic_opt_ie_len)
 1442                         ireq->i_len = ic->ic_opt_ie_len;
 1443                 error = copyout(ic->ic_opt_ie, ireq->i_data, ireq->i_len);
 1444                 break;
 1445         case IEEE80211_IOC_WPAKEY:
 1446                 error = ieee80211_ioctl_getkey(ic, ireq);
 1447                 break;
 1448         case IEEE80211_IOC_CHANINFO:
 1449                 error = ieee80211_ioctl_getchaninfo(ic, ireq);
 1450                 break;
 1451         case IEEE80211_IOC_BSSID:
 1452                 if (ireq->i_len != IEEE80211_ADDR_LEN)
 1453                         return EINVAL;
 1454                 error = copyout(ic->ic_state == IEEE80211_S_RUN ?
 1455                                         ic->ic_bss->ni_bssid :
 1456                                         ic->ic_des_bssid,
 1457                                 ireq->i_data, ireq->i_len);
 1458                 break;
 1459         case IEEE80211_IOC_WPAIE:
 1460                 error = ieee80211_ioctl_getwpaie(ic, ireq);
 1461                 break;
 1462         case IEEE80211_IOC_SCAN_RESULTS:
 1463                 error = ieee80211_ioctl_getscanresults(ic, ireq);
 1464                 break;
 1465         case IEEE80211_IOC_STA_STATS:
 1466                 error = ieee80211_ioctl_getstastats(ic, ireq);
 1467                 break;
 1468         case IEEE80211_IOC_TXPOWMAX:
 1469                 ireq->i_val = ic->ic_bss->ni_txpower;
 1470                 break;
 1471         case IEEE80211_IOC_STA_TXPOW:
 1472                 error = ieee80211_ioctl_getstatxpow(ic, ireq);
 1473                 break;
 1474         case IEEE80211_IOC_STA_INFO:
 1475                 error = ieee80211_ioctl_getstainfo(ic, ireq);
 1476                 break;
 1477         case IEEE80211_IOC_WME_CWMIN:           /* WME: CWmin */
 1478         case IEEE80211_IOC_WME_CWMAX:           /* WME: CWmax */
 1479         case IEEE80211_IOC_WME_AIFS:            /* WME: AIFS */
 1480         case IEEE80211_IOC_WME_TXOPLIMIT:       /* WME: txops limit */
 1481         case IEEE80211_IOC_WME_ACM:             /* WME: ACM (bss only) */
 1482         case IEEE80211_IOC_WME_ACKPOLICY:       /* WME: ACK policy (bss only) */
 1483                 error = ieee80211_ioctl_getwmeparam(ic, ireq);
 1484                 break;
 1485         case IEEE80211_IOC_DTIM_PERIOD:
 1486                 ireq->i_val = ic->ic_dtim_period;
 1487                 break;
 1488         case IEEE80211_IOC_BEACON_INTERVAL:
 1489                 /* NB: get from ic_bss for station mode */
 1490                 ireq->i_val = ic->ic_bss->ni_intval;
 1491                 break;
 1492         case IEEE80211_IOC_PUREG:
 1493                 ireq->i_val = (ic->ic_flags & IEEE80211_F_PUREG) != 0;
 1494                 break;
 1495         case IEEE80211_IOC_MCAST_RATE:
 1496                 ireq->i_val = ic->ic_mcast_rate;
 1497                 break;
 1498         case IEEE80211_IOC_FRAGTHRESHOLD:
 1499                 ireq->i_val = ic->ic_fragthreshold;
 1500                 break;
 1501         case IEEE80211_IOC_MACCMD:
 1502                 error = ieee80211_ioctl_getmaccmd(ic, ireq);
 1503                 break;
 1504         case IEEE80211_IOC_BURST:
 1505                 ireq->i_val = (ic->ic_flags & IEEE80211_F_BURST) != 0;
 1506                 break;
 1507         default:
 1508                 error = EINVAL;
 1509                 break;
 1510         }
 1511         return error;
 1512 }
 1513 
 1514 static int
 1515 ieee80211_ioctl_setoptie(struct ieee80211com *ic, struct ieee80211req *ireq)
 1516 {
 1517         int error;
 1518         void *ie, *oie;
 1519 
 1520         /*
 1521          * NB: Doing this for ap operation could be useful (e.g. for
 1522          *     WPA and/or WME) except that it typically is worthless
 1523          *     without being able to intervene when processing
 1524          *     association response frames--so disallow it for now.
 1525          */
 1526         if (ic->ic_opmode != IEEE80211_M_STA)
 1527                 return EINVAL;
 1528         if (ireq->i_len > IEEE80211_MAX_OPT_IE)
 1529                 return EINVAL;
 1530         if (ireq->i_len > 0) {
 1531                 MALLOC(ie, void *, ireq->i_len, M_DEVBUF, M_NOWAIT);
 1532                 if (ie == NULL)
 1533                         return ENOMEM;
 1534                 error = copyin(ireq->i_data, ie, ireq->i_len);
 1535                 if (error) {
 1536                         FREE(ie, M_DEVBUF);
 1537                         return error;
 1538                 }
 1539         } else {
 1540                 ie = NULL;
 1541                 ireq->i_len = 0;
 1542         }
 1543         /* XXX sanity check data? */
 1544         oie = ic->ic_opt_ie;
 1545         ic->ic_opt_ie = ie;
 1546         ic->ic_opt_ie_len = ireq->i_len;
 1547         if (oie != NULL)
 1548                 FREE(oie, M_DEVBUF);
 1549         return 0;
 1550 }
 1551 
 1552 static int
 1553 ieee80211_ioctl_setkey(struct ieee80211com *ic, struct ieee80211req *ireq)
 1554 {
 1555         struct ieee80211req_key ik;
 1556         struct ieee80211_node *ni;
 1557         struct ieee80211_key *wk;
 1558         u_int16_t kid;
 1559         int error;
 1560 
 1561         if (ireq->i_len != sizeof(ik))
 1562                 return EINVAL;
 1563         error = copyin(ireq->i_data, &ik, sizeof(ik));
 1564         if (error)
 1565                 return error;
 1566         /* NB: cipher support is verified by ieee80211_crypt_newkey */
 1567         /* NB: this also checks ik->ik_keylen > sizeof(wk->wk_key) */
 1568         if (ik.ik_keylen > sizeof(ik.ik_keydata))
 1569                 return E2BIG;
 1570         kid = ik.ik_keyix;
 1571         if (kid == IEEE80211_KEYIX_NONE) {
 1572                 /* XXX unicast keys currently must be tx/rx */
 1573                 if (ik.ik_flags != (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV))
 1574                         return EINVAL;
 1575                 if (ic->ic_opmode == IEEE80211_M_STA) {
 1576                         ni = ieee80211_ref_node(ic->ic_bss);
 1577                         if (!IEEE80211_ADDR_EQ(ik.ik_macaddr, ni->ni_bssid)) {
 1578                                 ieee80211_free_node(ni);
 1579                                 return EADDRNOTAVAIL;
 1580                         }
 1581                 } else {
 1582                         ni = ieee80211_find_node(&ic->ic_sta, ik.ik_macaddr);
 1583                         if (ni == NULL)
 1584                                 return ENOENT;
 1585                 }
 1586                 wk = &ni->ni_ucastkey;
 1587         } else {
 1588                 if (kid >= IEEE80211_WEP_NKID)
 1589                         return EINVAL;
 1590                 wk = &ic->ic_nw_keys[kid];
 1591                 /*
 1592                  * Global slots start off w/o any assigned key index.
 1593                  * Force one here for consistency with IEEE80211_IOC_WEPKEY.
 1594                  */
 1595                 if (wk->wk_keyix == IEEE80211_KEYIX_NONE)
 1596                         wk->wk_keyix = kid;
 1597                 ni = NULL;
 1598         }
 1599         error = 0;
 1600         ieee80211_key_update_begin(ic);
 1601         if (ieee80211_crypto_newkey(ic, ik.ik_type, ik.ik_flags, wk)) {
 1602                 wk->wk_keylen = ik.ik_keylen;
 1603                 /* NB: MIC presence is implied by cipher type */
 1604                 if (wk->wk_keylen > IEEE80211_KEYBUF_SIZE)
 1605                         wk->wk_keylen = IEEE80211_KEYBUF_SIZE;
 1606                 wk->wk_keyrsc = ik.ik_keyrsc;
 1607                 wk->wk_keytsc = 0;                      /* new key, reset */
 1608                 memset(wk->wk_key, 0, sizeof(wk->wk_key));
 1609                 memcpy(wk->wk_key, ik.ik_keydata, ik.ik_keylen);
 1610                 if (!ieee80211_crypto_setkey(ic, wk,
 1611                     ni != NULL ? ni->ni_macaddr : ik.ik_macaddr))
 1612                         error = EIO;
 1613                 else if ((ik.ik_flags & IEEE80211_KEY_DEFAULT))
 1614                         ic->ic_def_txkey = kid;
 1615         } else
 1616                 error = ENXIO;
 1617         ieee80211_key_update_end(ic);
 1618         if (ni != NULL)
 1619                 ieee80211_free_node(ni);
 1620         return error;
 1621 }
 1622 
 1623 static int
 1624 ieee80211_ioctl_delkey(struct ieee80211com *ic, struct ieee80211req *ireq)
 1625 {
 1626         struct ieee80211req_del_key dk;
 1627         int kid, error;
 1628 
 1629         if (ireq->i_len != sizeof(dk))
 1630                 return EINVAL;
 1631         error = copyin(ireq->i_data, &dk, sizeof(dk));
 1632         if (error)
 1633                 return error;
 1634         kid = dk.idk_keyix;
 1635         /* XXX u_int8_t -> u_int16_t */
 1636         if (dk.idk_keyix == (u_int8_t) IEEE80211_KEYIX_NONE) {
 1637                 struct ieee80211_node *ni;
 1638 
 1639                 if (ic->ic_opmode == IEEE80211_M_STA) {
 1640                         ni = ieee80211_ref_node(ic->ic_bss);
 1641                         if (!IEEE80211_ADDR_EQ(dk.idk_macaddr, ni->ni_bssid)) {
 1642                                 ieee80211_free_node(ni);
 1643                                 return EADDRNOTAVAIL;
 1644                         }
 1645                 } else {
 1646                         ni = ieee80211_find_node(&ic->ic_sta, dk.idk_macaddr);
 1647                         if (ni == NULL)
 1648                                 return ENOENT;
 1649                 }
 1650                 /* XXX error return */
 1651                 ieee80211_node_delucastkey(ni);
 1652                 ieee80211_free_node(ni);
 1653         } else {
 1654                 if (kid >= IEEE80211_WEP_NKID)
 1655                         return EINVAL;
 1656                 /* XXX error return */
 1657                 ieee80211_crypto_delkey(ic, &ic->ic_nw_keys[kid]);
 1658         }
 1659         return 0;
 1660 }
 1661 
 1662 static void
 1663 domlme(void *arg, struct ieee80211_node *ni)
 1664 {
 1665         struct ieee80211com *ic = ni->ni_ic;
 1666         struct ieee80211req_mlme *mlme = arg;
 1667 
 1668         if (ni->ni_associd != 0) {
 1669                 IEEE80211_SEND_MGMT(ic, ni,
 1670                         mlme->im_op == IEEE80211_MLME_DEAUTH ?
 1671                                 IEEE80211_FC0_SUBTYPE_DEAUTH :
 1672                                 IEEE80211_FC0_SUBTYPE_DISASSOC,
 1673                         mlme->im_reason);
 1674         }
 1675         ieee80211_node_leave(ic, ni);
 1676 }
 1677 
 1678 static int
 1679 ieee80211_ioctl_setmlme(struct ieee80211com *ic, struct ieee80211req *ireq)
 1680 {
 1681         struct ieee80211req_mlme mlme;
 1682         struct ieee80211_node *ni;
 1683         int error;
 1684 
 1685         if (ireq->i_len != sizeof(mlme))
 1686                 return EINVAL;
 1687         error = copyin(ireq->i_data, &mlme, sizeof(mlme));
 1688         if (error)
 1689                 return error;
 1690         switch (mlme.im_op) {
 1691         case IEEE80211_MLME_ASSOC:
 1692                 if (ic->ic_opmode != IEEE80211_M_STA)
 1693                         return EINVAL;
 1694                 /* XXX must be in S_SCAN state? */
 1695 
 1696                 if (mlme.im_ssid_len != 0) {
 1697                         /*
 1698                          * Desired ssid specified; must match both bssid and
 1699                          * ssid to distinguish ap advertising multiple ssid's.
 1700                          */
 1701                         ni = ieee80211_find_node_with_ssid(&ic->ic_scan,
 1702                                 mlme.im_macaddr,
 1703                                 mlme.im_ssid_len, mlme.im_ssid);
 1704                 } else {
 1705                         /*
 1706                          * Normal case; just match bssid.
 1707                          */
 1708                         ni = ieee80211_find_node(&ic->ic_scan, mlme.im_macaddr);
 1709                 }
 1710                 if (ni == NULL)
 1711                         return EINVAL;
 1712                 if (!ieee80211_sta_join(ic, ni)) {
 1713                         ieee80211_free_node(ni);
 1714                         return EINVAL;
 1715                 }
 1716                 break;
 1717         case IEEE80211_MLME_DISASSOC:
 1718         case IEEE80211_MLME_DEAUTH:
 1719                 switch (ic->ic_opmode) {
 1720                 case IEEE80211_M_STA:
 1721                         /* XXX not quite right */
 1722                         ieee80211_new_state(ic, IEEE80211_S_INIT,
 1723                                 mlme.im_reason);
 1724                         break;
 1725                 case IEEE80211_M_HOSTAP:
 1726                         /* NB: the broadcast address means do 'em all */
 1727                         if (!IEEE80211_ADDR_EQ(mlme.im_macaddr, ic->ic_ifp->if_broadcastaddr)) {
 1728                                 if ((ni = ieee80211_find_node(&ic->ic_sta,
 1729                                                 mlme.im_macaddr)) == NULL)
 1730                                         return EINVAL;
 1731                                 domlme(&mlme, ni);
 1732                                 ieee80211_free_node(ni);
 1733                         } else {
 1734                                 ieee80211_iterate_nodes(&ic->ic_sta,
 1735                                                 domlme, &mlme);
 1736                         }
 1737                         break;
 1738                 default:
 1739                         return EINVAL;
 1740                 }
 1741                 break;
 1742         case IEEE80211_MLME_AUTHORIZE:
 1743         case IEEE80211_MLME_UNAUTHORIZE:
 1744                 if (ic->ic_opmode != IEEE80211_M_HOSTAP)
 1745                         return EINVAL;
 1746                 ni = ieee80211_find_node(&ic->ic_sta, mlme.im_macaddr);
 1747                 if (ni == NULL)
 1748                         return EINVAL;
 1749                 if (mlme.im_op == IEEE80211_MLME_AUTHORIZE)
 1750                         ieee80211_node_authorize(ni);
 1751                 else
 1752                         ieee80211_node_unauthorize(ni);
 1753                 ieee80211_free_node(ni);
 1754                 break;
 1755         default:
 1756                 return EINVAL;
 1757         }
 1758         return 0;
 1759 }
 1760 
 1761 static int
 1762 ieee80211_ioctl_macmac(struct ieee80211com *ic, struct ieee80211req *ireq)
 1763 {
 1764         u_int8_t mac[IEEE80211_ADDR_LEN];
 1765         const struct ieee80211_aclator *acl = ic->ic_acl;
 1766         int error;
 1767 
 1768         if (ireq->i_len != sizeof(mac))
 1769                 return EINVAL;
 1770         error = copyin(ireq->i_data, mac, ireq->i_len);
 1771         if (error)
 1772                 return error;
 1773         if (acl == NULL) {
 1774                 acl = ieee80211_aclator_get("mac");
 1775                 if (acl == NULL || !acl->iac_attach(ic))
 1776                         return EINVAL;
 1777                 ic->ic_acl = acl;
 1778         }
 1779         if (ireq->i_type == IEEE80211_IOC_ADDMAC)
 1780                 acl->iac_add(ic, mac);
 1781         else
 1782                 acl->iac_remove(ic, mac);
 1783         return 0;
 1784 }
 1785 
 1786 static int
 1787 ieee80211_ioctl_setmaccmd(struct ieee80211com *ic, struct ieee80211req *ireq)
 1788 {
 1789         const struct ieee80211_aclator *acl = ic->ic_acl;
 1790 
 1791         switch (ireq->i_val) {
 1792         case IEEE80211_MACCMD_POLICY_OPEN:
 1793         case IEEE80211_MACCMD_POLICY_ALLOW:
 1794         case IEEE80211_MACCMD_POLICY_DENY:
 1795                 if (acl == NULL) {
 1796                         acl = ieee80211_aclator_get("mac");
 1797                         if (acl == NULL || !acl->iac_attach(ic))
 1798                                 return EINVAL;
 1799                         ic->ic_acl = acl;
 1800                 }
 1801                 acl->iac_setpolicy(ic, ireq->i_val);
 1802                 break;
 1803         case IEEE80211_MACCMD_FLUSH:
 1804                 if (acl != NULL)
 1805                         acl->iac_flush(ic);
 1806                 /* NB: silently ignore when not in use */
 1807                 break;
 1808         case IEEE80211_MACCMD_DETACH:
 1809                 if (acl != NULL) {
 1810                         ic->ic_acl = NULL;
 1811                         acl->iac_detach(ic);
 1812                 }
 1813                 break;
 1814         default:
 1815                 if (acl == NULL)
 1816                         return EINVAL;
 1817                 else
 1818                         return acl->iac_setioctl(ic, ireq);
 1819         }
 1820         return 0;
 1821 }
 1822 
 1823 static int
 1824 ieee80211_ioctl_setchanlist(struct ieee80211com *ic, struct ieee80211req *ireq)
 1825 {
 1826         struct ieee80211req_chanlist list;
 1827         u_char chanlist[IEEE80211_CHAN_BYTES];
 1828         int i, j, error;
 1829 
 1830         if (ireq->i_len != sizeof(list))
 1831                 return EINVAL;
 1832         error = copyin(ireq->i_data, &list, sizeof(list));
 1833         if (error)
 1834                 return error;
 1835         memset(chanlist, 0, sizeof(chanlist));
 1836         /*
 1837          * Since channel 0 is not available for DS, channel 1
 1838          * is assigned to LSB on WaveLAN.
 1839          */
 1840         if (ic->ic_phytype == IEEE80211_T_DS)
 1841                 i = 1;
 1842         else
 1843                 i = 0;
 1844         for (j = 0; i <= IEEE80211_CHAN_MAX; i++, j++) {
 1845                 /*
 1846                  * NB: silently discard unavailable channels so users
 1847                  *     can specify 1-255 to get all available channels.
 1848                  */
 1849                 if (isset(list.ic_channels, j) && isset(ic->ic_chan_avail, i))
 1850                         setbit(chanlist, i);
 1851         }
 1852         if (ic->ic_ibss_chan == NULL ||
 1853             isclr(chanlist, ieee80211_chan2ieee(ic, ic->ic_ibss_chan))) {
 1854                 for (i = 0; i <= IEEE80211_CHAN_MAX; i++)
 1855                         if (isset(chanlist, i)) {
 1856                                 ic->ic_ibss_chan = &ic->ic_channels[i];
 1857                                 goto found;
 1858                         }
 1859                 return EINVAL;                  /* no active channels */
 1860 found:
 1861                 ;
 1862         }
 1863         memcpy(ic->ic_chan_active, chanlist, sizeof(ic->ic_chan_active));
 1864         return IS_UP_AUTO(ic) ? ENETRESET : 0;
 1865 }
 1866 
 1867 static int
 1868 ieee80211_ioctl_setstastats(struct ieee80211com *ic, struct ieee80211req *ireq)
 1869 {
 1870         struct ieee80211_node *ni;
 1871         u_int8_t macaddr[IEEE80211_ADDR_LEN];
 1872         int error;
 1873 
 1874         /*
 1875          * NB: we could copyin ieee80211req_sta_stats so apps
 1876          *     could make selective changes but that's overkill;
 1877          *     just clear all stats for now.
 1878          */
 1879         if (ireq->i_len < IEEE80211_ADDR_LEN)
 1880                 return EINVAL;
 1881         error = copyin(ireq->i_data, macaddr, IEEE80211_ADDR_LEN);
 1882         if (error != 0)
 1883                 return error;
 1884         ni = ieee80211_find_node(&ic->ic_sta, macaddr);
 1885         if (ni == NULL)
 1886                 return EINVAL;          /* XXX */
 1887         memset(&ni->ni_stats, 0, sizeof(ni->ni_stats));
 1888         ieee80211_free_node(ni);
 1889         return 0;
 1890 }
 1891 
 1892 static int
 1893 ieee80211_ioctl_setstatxpow(struct ieee80211com *ic, struct ieee80211req *ireq)
 1894 {
 1895         struct ieee80211_node *ni;
 1896         struct ieee80211req_sta_txpow txpow;
 1897         int error;
 1898 
 1899         if (ireq->i_len != sizeof(txpow))
 1900                 return EINVAL;
 1901         error = copyin(ireq->i_data, &txpow, sizeof(txpow));
 1902         if (error != 0)
 1903                 return error;
 1904         ni = ieee80211_find_node(&ic->ic_sta, txpow.it_macaddr);
 1905         if (ni == NULL)
 1906                 return EINVAL;          /* XXX */
 1907         ni->ni_txpower = txpow.it_txpow;
 1908         ieee80211_free_node(ni);
 1909         return error;
 1910 }
 1911 
 1912 static int
 1913 ieee80211_ioctl_setwmeparam(struct ieee80211com *ic, struct ieee80211req *ireq)
 1914 {
 1915         struct ieee80211_wme_state *wme = &ic->ic_wme;
 1916         struct wmeParams *wmep, *chanp;
 1917         int isbss, ac;
 1918 
 1919         if ((ic->ic_caps & IEEE80211_C_WME) == 0)
 1920                 return EINVAL;
 1921 
 1922         isbss = (ireq->i_len & IEEE80211_WMEPARAM_BSS);
 1923         ac = (ireq->i_len & IEEE80211_WMEPARAM_VAL);
 1924         if (ac >= WME_NUM_AC)
 1925                 ac = WME_AC_BE;
 1926         if (isbss) {
 1927                 chanp = &wme->wme_bssChanParams.cap_wmeParams[ac];
 1928                 wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[ac];
 1929         } else {
 1930                 chanp = &wme->wme_chanParams.cap_wmeParams[ac];
 1931                 wmep = &wme->wme_wmeChanParams.cap_wmeParams[ac];
 1932         }
 1933         switch (ireq->i_type) {
 1934         case IEEE80211_IOC_WME_CWMIN:           /* WME: CWmin */
 1935                 if (isbss) {
 1936                         wmep->wmep_logcwmin = ireq->i_val;
 1937                         if ((wme->wme_flags & WME_F_AGGRMODE) == 0)
 1938                                 chanp->wmep_logcwmin = ireq->i_val;
 1939                 } else {
 1940                         wmep->wmep_logcwmin = chanp->wmep_logcwmin =
 1941                                 ireq->i_val;
 1942                 }
 1943                 break;
 1944         case IEEE80211_IOC_WME_CWMAX:           /* WME: CWmax */
 1945                 if (isbss) {
 1946                         wmep->wmep_logcwmax = ireq->i_val;
 1947                         if ((wme->wme_flags & WME_F_AGGRMODE) == 0)
 1948                                 chanp->wmep_logcwmax = ireq->i_val;
 1949                 } else {
 1950                         wmep->wmep_logcwmax = chanp->wmep_logcwmax =
 1951                                 ireq->i_val;
 1952                 }
 1953                 break;
 1954         case IEEE80211_IOC_WME_AIFS:            /* WME: AIFS */
 1955                 if (isbss) {
 1956                         wmep->wmep_aifsn = ireq->i_val;
 1957                         if ((wme->wme_flags & WME_F_AGGRMODE) == 0)
 1958                                 chanp->wmep_aifsn = ireq->i_val;
 1959                 } else {
 1960                         wmep->wmep_aifsn = chanp->wmep_aifsn = ireq->i_val;
 1961                 }
 1962                 break;
 1963         case IEEE80211_IOC_WME_TXOPLIMIT:       /* WME: txops limit */
 1964                 if (isbss) {
 1965                         wmep->wmep_txopLimit = ireq->i_val;
 1966                         if ((wme->wme_flags & WME_F_AGGRMODE) == 0)
 1967                                 chanp->wmep_txopLimit = ireq->i_val;
 1968                 } else {
 1969                         wmep->wmep_txopLimit = chanp->wmep_txopLimit =
 1970                                 ireq->i_val;
 1971                 }
 1972                 break;
 1973         case IEEE80211_IOC_WME_ACM:             /* WME: ACM (bss only) */
 1974                 wmep->wmep_acm = ireq->i_val;
 1975                 if ((wme->wme_flags & WME_F_AGGRMODE) == 0)
 1976                         chanp->wmep_acm = ireq->i_val;
 1977                 break;
 1978         case IEEE80211_IOC_WME_ACKPOLICY:       /* WME: ACK policy (!bss only)*/
 1979                 wmep->wmep_noackPolicy = chanp->wmep_noackPolicy =
 1980                         (ireq->i_val) == 0;
 1981                 break;
 1982         }
 1983         ieee80211_wme_updateparams(ic);
 1984         return 0;
 1985 }
 1986 
 1987 static int
 1988 cipher2cap(int cipher)
 1989 {
 1990         switch (cipher) {
 1991         case IEEE80211_CIPHER_WEP:      return IEEE80211_C_WEP;
 1992         case IEEE80211_CIPHER_AES_OCB:  return IEEE80211_C_AES;
 1993         case IEEE80211_CIPHER_AES_CCM:  return IEEE80211_C_AES_CCM;
 1994         case IEEE80211_CIPHER_CKIP:     return IEEE80211_C_CKIP;
 1995         case IEEE80211_CIPHER_TKIP:     return IEEE80211_C_TKIP;
 1996         }
 1997         return 0;
 1998 }
 1999 
 2000 static int
 2001 ieee80211_ioctl_set80211(struct ieee80211com *ic, u_long cmd, struct ieee80211req *ireq)
 2002 {
 2003         static const u_int8_t zerobssid[IEEE80211_ADDR_LEN];
 2004         struct ieee80211_rsnparms *rsn = &ic->ic_bss->ni_rsn;
 2005         int error;
 2006         const struct ieee80211_authenticator *auth;
 2007         u_int8_t tmpkey[IEEE80211_KEYBUF_SIZE];
 2008         char tmpssid[IEEE80211_NWID_LEN];
 2009         u_int8_t tmpbssid[IEEE80211_ADDR_LEN];
 2010         struct ieee80211_key *k;
 2011         int j, caps;
 2012         u_int kid;
 2013 
 2014         error = 0;
 2015         switch (ireq->i_type) {
 2016         case IEEE80211_IOC_SSID:
 2017                 if (ireq->i_val != 0 ||
 2018                     ireq->i_len > IEEE80211_NWID_LEN)
 2019                         return EINVAL;
 2020                 error = copyin(ireq->i_data, tmpssid, ireq->i_len);
 2021                 if (error)
 2022                         break;
 2023                 memset(ic->ic_des_essid, 0, IEEE80211_NWID_LEN);
 2024                 ic->ic_des_esslen = ireq->i_len;
 2025                 memcpy(ic->ic_des_essid, tmpssid, ireq->i_len);
 2026                 error = ENETRESET;
 2027                 break;
 2028         case IEEE80211_IOC_WEP:
 2029                 switch (ireq->i_val) {
 2030                 case IEEE80211_WEP_OFF:
 2031                         ic->ic_flags &= ~IEEE80211_F_PRIVACY;
 2032                         ic->ic_flags &= ~IEEE80211_F_DROPUNENC;
 2033                         break;
 2034                 case IEEE80211_WEP_ON:
 2035                         ic->ic_flags |= IEEE80211_F_PRIVACY;
 2036                         ic->ic_flags |= IEEE80211_F_DROPUNENC;
 2037                         break;
 2038                 case IEEE80211_WEP_MIXED:
 2039                         ic->ic_flags |= IEEE80211_F_PRIVACY;
 2040                         ic->ic_flags &= ~IEEE80211_F_DROPUNENC;
 2041                         break;
 2042                 }
 2043                 error = ENETRESET;
 2044                 break;
 2045         case IEEE80211_IOC_WEPKEY:
 2046                 kid = (u_int) ireq->i_val;
 2047                 if (kid >= IEEE80211_WEP_NKID)
 2048                         return EINVAL;
 2049                 k = &ic->ic_nw_keys[kid];
 2050                 if (ireq->i_len == 0) {
 2051                         /* zero-len =>'s delete any existing key */
 2052                         (void) ieee80211_crypto_delkey(ic, k);
 2053                         break;
 2054                 }
 2055                 if (ireq->i_len > sizeof(tmpkey))
 2056                         return EINVAL;
 2057                 memset(tmpkey, 0, sizeof(tmpkey));
 2058                 error = copyin(ireq->i_data, tmpkey, ireq->i_len);
 2059                 if (error)
 2060                         break;
 2061                 ieee80211_key_update_begin(ic);
 2062                 k->wk_keyix = kid;      /* NB: force fixed key id */
 2063                 if (ieee80211_crypto_newkey(ic, IEEE80211_CIPHER_WEP,
 2064                     IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV, k)) {
 2065                         k->wk_keylen = ireq->i_len;
 2066                         memcpy(k->wk_key, tmpkey, sizeof(tmpkey));
 2067                         if  (!ieee80211_crypto_setkey(ic, k, ic->ic_myaddr))
 2068                                 error = EINVAL;
 2069                 } else
 2070                         error = EINVAL;
 2071                 ieee80211_key_update_end(ic);
 2072                 if (!error)                     /* NB: for compatibility */
 2073                         error = ENETRESET;
 2074                 break;
 2075         case IEEE80211_IOC_WEPTXKEY:
 2076                 kid = (u_int) ireq->i_val;
 2077                 if (kid >= IEEE80211_WEP_NKID &&
 2078                     (u_int16_t) kid != IEEE80211_KEYIX_NONE)
 2079                         return EINVAL;
 2080                 ic->ic_def_txkey = kid;
 2081                 error = ENETRESET;      /* push to hardware */
 2082                 break;
 2083         case IEEE80211_IOC_AUTHMODE:
 2084                 switch (ireq->i_val) {
 2085                 case IEEE80211_AUTH_WPA:
 2086                 case IEEE80211_AUTH_8021X:      /* 802.1x */
 2087                 case IEEE80211_AUTH_OPEN:       /* open */
 2088                 case IEEE80211_AUTH_SHARED:     /* shared-key */
 2089                 case IEEE80211_AUTH_AUTO:       /* auto */
 2090                         auth = ieee80211_authenticator_get(ireq->i_val);
 2091                         if (auth == NULL)
 2092                                 return EINVAL;
 2093                         break;
 2094                 default:
 2095                         return EINVAL;
 2096                 }
 2097                 switch (ireq->i_val) {
 2098                 case IEEE80211_AUTH_WPA:        /* WPA w/ 802.1x */
 2099                         ic->ic_flags |= IEEE80211_F_PRIVACY;
 2100                         ireq->i_val = IEEE80211_AUTH_8021X;
 2101                         break;
 2102                 case IEEE80211_AUTH_OPEN:       /* open */
 2103                         ic->ic_flags &= ~(IEEE80211_F_WPA|IEEE80211_F_PRIVACY);
 2104                         break;
 2105                 case IEEE80211_AUTH_SHARED:     /* shared-key */
 2106                 case IEEE80211_AUTH_8021X:      /* 802.1x */
 2107                         ic->ic_flags &= ~IEEE80211_F_WPA;
 2108                         /* both require a key so mark the PRIVACY capability */
 2109                         ic->ic_flags |= IEEE80211_F_PRIVACY;
 2110                         break;
 2111                 case IEEE80211_AUTH_AUTO:       /* auto */
 2112                         ic->ic_flags &= ~IEEE80211_F_WPA;
 2113                         /* XXX PRIVACY handling? */
 2114                         /* XXX what's the right way to do this? */
 2115                         break;
 2116                 }
 2117                 /* NB: authenticator attach/detach happens on state change */
 2118                 ic->ic_bss->ni_authmode = ireq->i_val;
 2119                 /* XXX mixed/mode/usage? */
 2120                 ic->ic_auth = auth;
 2121                 error = ENETRESET;
 2122                 break;
 2123         case IEEE80211_IOC_CHANNEL:
 2124                 /* XXX 0xffff overflows 16-bit signed */
 2125                 if (ireq->i_val == 0 ||
 2126                     ireq->i_val == (int16_t) IEEE80211_CHAN_ANY)
 2127                         ic->ic_des_chan = IEEE80211_CHAN_ANYC;
 2128                 else if ((u_int) ireq->i_val > IEEE80211_CHAN_MAX ||
 2129                     isclr(ic->ic_chan_active, ireq->i_val)) {
 2130                         return EINVAL;
 2131                 } else
 2132                         ic->ic_ibss_chan = ic->ic_des_chan =
 2133                                 &ic->ic_channels[ireq->i_val];
 2134                 switch (ic->ic_state) {
 2135                 case IEEE80211_S_INIT:
 2136                 case IEEE80211_S_SCAN:
 2137                         error = ENETRESET;
 2138                         break;
 2139                 default:
 2140                         /*
 2141                          * If the desired channel has changed (to something
 2142                          * other than any) and we're not already scanning,
 2143                          * then kick the state machine.
 2144                          */
 2145                         if (ic->ic_des_chan != IEEE80211_CHAN_ANYC &&
 2146                             ic->ic_bss->ni_chan != ic->ic_des_chan &&
 2147                             (ic->ic_flags & IEEE80211_F_SCAN) == 0)
 2148                                 error = ENETRESET;
 2149                         break;
 2150                 }
 2151                 if (error == ENETRESET &&
 2152                         ic->ic_opmode == IEEE80211_M_MONITOR) {
 2153                         if (IS_UP(ic)) {
 2154                                 /*
 2155                                  * Monitor mode can switch directly.
 2156                                  */
 2157                                 if (ic->ic_des_chan != IEEE80211_CHAN_ANYC)
 2158                                         ic->ic_curchan = ic->ic_des_chan;
 2159                                 error = ic->ic_reset(ic->ic_ifp);
 2160                         } else
 2161                                 error = 0;
 2162                 }
 2163                 break;
 2164         case IEEE80211_IOC_POWERSAVE:
 2165                 switch (ireq->i_val) {
 2166                 case IEEE80211_POWERSAVE_OFF:
 2167                         if (ic->ic_flags & IEEE80211_F_PMGTON) {
 2168                                 ic->ic_flags &= ~IEEE80211_F_PMGTON;
 2169                                 error = ENETRESET;
 2170                         }
 2171                         break;
 2172                 case IEEE80211_POWERSAVE_ON:
 2173                         if ((ic->ic_caps & IEEE80211_C_PMGT) == 0)
 2174                                 error = EINVAL;
 2175                         else if ((ic->ic_flags & IEEE80211_F_PMGTON) == 0) {
 2176                                 ic->ic_flags |= IEEE80211_F_PMGTON;
 2177                                 error = ENETRESET;
 2178                         }
 2179                         break;
 2180                 default:
 2181                         error = EINVAL;
 2182                         break;
 2183                 }
 2184                 break;
 2185         case IEEE80211_IOC_POWERSAVESLEEP:
 2186                 if (ireq->i_val < 0)
 2187                         return EINVAL;
 2188                 ic->ic_lintval = ireq->i_val;
 2189                 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
 2190                 break;
 2191         case IEEE80211_IOC_RTSTHRESHOLD:
 2192                 if (!(IEEE80211_RTS_MIN <= ireq->i_val &&
 2193                       ireq->i_val <= IEEE80211_RTS_MAX))
 2194                         return EINVAL;
 2195                 ic->ic_rtsthreshold = ireq->i_val;
 2196                 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
 2197                 break;
 2198         case IEEE80211_IOC_PROTMODE:
 2199                 if (ireq->i_val > IEEE80211_PROT_RTSCTS)
 2200                         return EINVAL;
 2201                 ic->ic_protmode = ireq->i_val;
 2202                 /* NB: if not operating in 11g this can wait */
 2203                 if (ic->ic_curmode == IEEE80211_MODE_11G)
 2204                         error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
 2205                 break;
 2206         case IEEE80211_IOC_TXPOWER:
 2207                 if ((ic->ic_caps & IEEE80211_C_TXPMGT) == 0)
 2208                         return EINVAL;
 2209                 if (!(IEEE80211_TXPOWER_MIN < ireq->i_val &&
 2210                       ireq->i_val < IEEE80211_TXPOWER_MAX))
 2211                         return EINVAL;
 2212                 ic->ic_txpowlimit = ireq->i_val;
 2213                 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
 2214                 break;
 2215         case IEEE80211_IOC_ROAMING:
 2216                 if (!(IEEE80211_ROAMING_DEVICE <= ireq->i_val &&
 2217                     ireq->i_val <= IEEE80211_ROAMING_MANUAL))
 2218                         return EINVAL;
 2219                 ic->ic_roaming = ireq->i_val;
 2220                 /* XXXX reset? */
 2221                 break;
 2222         case IEEE80211_IOC_PRIVACY:
 2223                 if (ireq->i_val) {
 2224                         /* XXX check for key state? */
 2225                         ic->ic_flags |= IEEE80211_F_PRIVACY;
 2226                 } else
 2227                         ic->ic_flags &= ~IEEE80211_F_PRIVACY;
 2228                 break;
 2229         case IEEE80211_IOC_DROPUNENCRYPTED:
 2230                 if (ireq->i_val)
 2231                         ic->ic_flags |= IEEE80211_F_DROPUNENC;
 2232                 else
 2233                         ic->ic_flags &= ~IEEE80211_F_DROPUNENC;
 2234                 break;
 2235         case IEEE80211_IOC_WPAKEY:
 2236                 error = ieee80211_ioctl_setkey(ic, ireq);
 2237                 break;
 2238         case IEEE80211_IOC_DELKEY:
 2239                 error = ieee80211_ioctl_delkey(ic, ireq);
 2240                 break;
 2241         case IEEE80211_IOC_MLME:
 2242                 error = ieee80211_ioctl_setmlme(ic, ireq);
 2243                 break;
 2244         case IEEE80211_IOC_OPTIE:
 2245                 error = ieee80211_ioctl_setoptie(ic, ireq);
 2246                 break;
 2247         case IEEE80211_IOC_COUNTERMEASURES:
 2248                 if (ireq->i_val) {
 2249                         if ((ic->ic_flags & IEEE80211_F_WPA) == 0)
 2250                                 return EINVAL;
 2251                         ic->ic_flags |= IEEE80211_F_COUNTERM;
 2252                 } else
 2253                         ic->ic_flags &= ~IEEE80211_F_COUNTERM;
 2254                 break;
 2255         case IEEE80211_IOC_WPA:
 2256                 if (ireq->i_val > 3)
 2257                         return EINVAL;
 2258                 /* XXX verify ciphers available */
 2259                 ic->ic_flags &= ~IEEE80211_F_WPA;
 2260                 switch (ireq->i_val) {
 2261                 case 1:
 2262                         ic->ic_flags |= IEEE80211_F_WPA1;
 2263                         break;
 2264                 case 2:
 2265                         ic->ic_flags |= IEEE80211_F_WPA2;
 2266                         break;
 2267                 case 3:
 2268                         ic->ic_flags |= IEEE80211_F_WPA1 | IEEE80211_F_WPA2;
 2269                         break;
 2270                 }
 2271                 error = ENETRESET;              /* XXX? */
 2272                 break;
 2273         case IEEE80211_IOC_WME:
 2274                 if (ireq->i_val) {
 2275                         if ((ic->ic_caps & IEEE80211_C_WME) == 0)
 2276                                 return EINVAL;
 2277                         ic->ic_flags |= IEEE80211_F_WME;
 2278                 } else
 2279                         ic->ic_flags &= ~IEEE80211_F_WME;
 2280                 error = ENETRESET;              /* XXX maybe not for station? */
 2281                 break;
 2282         case IEEE80211_IOC_HIDESSID:
 2283                 if (ireq->i_val)
 2284                         ic->ic_flags |= IEEE80211_F_HIDESSID;
 2285                 else
 2286                         ic->ic_flags &= ~IEEE80211_F_HIDESSID;
 2287                 error = ENETRESET;
 2288                 break;
 2289         case IEEE80211_IOC_APBRIDGE:
 2290                 if (ireq->i_val == 0)
 2291                         ic->ic_flags |= IEEE80211_F_NOBRIDGE;
 2292                 else
 2293                         ic->ic_flags &= ~IEEE80211_F_NOBRIDGE;
 2294                 break;
 2295         case IEEE80211_IOC_MCASTCIPHER:
 2296                 if ((ic->ic_caps & cipher2cap(ireq->i_val)) == 0 &&
 2297                     !ieee80211_crypto_available(ireq->i_val))
 2298                         return EINVAL;
 2299                 rsn->rsn_mcastcipher = ireq->i_val;
 2300                 error = (ic->ic_flags & IEEE80211_F_WPA) ? ENETRESET : 0;
 2301                 break;
 2302         case IEEE80211_IOC_MCASTKEYLEN:
 2303                 if (!(0 < ireq->i_val && ireq->i_val < IEEE80211_KEYBUF_SIZE))
 2304                         return EINVAL;
 2305                 /* XXX no way to verify driver capability */
 2306                 rsn->rsn_mcastkeylen = ireq->i_val;
 2307                 error = (ic->ic_flags & IEEE80211_F_WPA) ? ENETRESET : 0;
 2308                 break;
 2309         case IEEE80211_IOC_UCASTCIPHERS:
 2310                 /*
 2311                  * Convert user-specified cipher set to the set
 2312                  * we can support (via hardware or software).
 2313                  * NB: this logic intentionally ignores unknown and
 2314                  * unsupported ciphers so folks can specify 0xff or
 2315                  * similar and get all available ciphers.
 2316                  */
 2317                 caps = 0;
 2318                 for (j = 1; j < 32; j++)        /* NB: skip WEP */
 2319                         if ((ireq->i_val & (1<<j)) &&
 2320                             ((ic->ic_caps & cipher2cap(j)) ||
 2321                              ieee80211_crypto_available(j)))
 2322                                 caps |= 1<<j;
 2323                 if (caps == 0)                  /* nothing available */
 2324                         return EINVAL;
 2325                 /* XXX verify ciphers ok for unicast use? */
 2326                 /* XXX disallow if running as it'll have no effect */
 2327                 rsn->rsn_ucastcipherset = caps;
 2328                 error = (ic->ic_flags & IEEE80211_F_WPA) ? ENETRESET : 0;
 2329                 break;
 2330         case IEEE80211_IOC_UCASTCIPHER:
 2331                 if ((rsn->rsn_ucastcipherset & cipher2cap(ireq->i_val)) == 0)
 2332                         return EINVAL;
 2333                 rsn->rsn_ucastcipher = ireq->i_val;
 2334                 break;
 2335         case IEEE80211_IOC_UCASTKEYLEN:
 2336                 if (!(0 < ireq->i_val && ireq->i_val < IEEE80211_KEYBUF_SIZE))
 2337                         return EINVAL;
 2338                 /* XXX no way to verify driver capability */
 2339                 rsn->rsn_ucastkeylen = ireq->i_val;
 2340                 break;
 2341         case IEEE80211_IOC_DRIVER_CAPS:
 2342                 /* NB: for testing */
 2343                 ic->ic_caps = (((u_int16_t) ireq->i_val) << 16) |
 2344                                ((u_int16_t) ireq->i_len);
 2345                 break;
 2346         case IEEE80211_IOC_KEYMGTALGS:
 2347                 /* XXX check */
 2348                 rsn->rsn_keymgmtset = ireq->i_val;
 2349                 error = (ic->ic_flags & IEEE80211_F_WPA) ? ENETRESET : 0;
 2350                 break;
 2351         case IEEE80211_IOC_RSNCAPS:
 2352                 /* XXX check */
 2353                 rsn->rsn_caps = ireq->i_val;
 2354                 error = (ic->ic_flags & IEEE80211_F_WPA) ? ENETRESET : 0;
 2355                 break;
 2356         case IEEE80211_IOC_BSSID:
 2357                 if (ireq->i_len != sizeof(tmpbssid))
 2358                         return EINVAL;
 2359                 error = copyin(ireq->i_data, tmpbssid, ireq->i_len);
 2360                 if (error)
 2361                         break;
 2362                 IEEE80211_ADDR_COPY(ic->ic_des_bssid, tmpbssid);
 2363                 if (IEEE80211_ADDR_EQ(ic->ic_des_bssid, zerobssid))
 2364                         ic->ic_flags &= ~IEEE80211_F_DESBSSID;
 2365                 else
 2366                         ic->ic_flags |= IEEE80211_F_DESBSSID;
 2367                 error = ENETRESET;
 2368                 break;
 2369         case IEEE80211_IOC_CHANLIST:
 2370                 error = ieee80211_ioctl_setchanlist(ic, ireq);
 2371                 break;
 2372         case IEEE80211_IOC_SCAN_REQ:
 2373                 if (ic->ic_opmode == IEEE80211_M_HOSTAP)        /* XXX ignore */
 2374                         break;
 2375                 error = ieee80211_setupscan(ic, ic->ic_chan_avail);
 2376                 if (error == 0)         /* XXX background scan */
 2377                         error = ieee80211_new_state(ic, IEEE80211_S_SCAN, -1);
 2378                 break;
 2379         case IEEE80211_IOC_ADDMAC:
 2380         case IEEE80211_IOC_DELMAC:
 2381                 error = ieee80211_ioctl_macmac(ic, ireq);
 2382                 break;
 2383         case IEEE80211_IOC_MACCMD:
 2384                 error = ieee80211_ioctl_setmaccmd(ic, ireq);
 2385                 break;
 2386         case IEEE80211_IOC_STA_STATS:
 2387                 error = ieee80211_ioctl_setstastats(ic, ireq);
 2388                 break;
 2389         case IEEE80211_IOC_STA_TXPOW:
 2390                 error = ieee80211_ioctl_setstatxpow(ic, ireq);
 2391                 break;
 2392         case IEEE80211_IOC_WME_CWMIN:           /* WME: CWmin */
 2393         case IEEE80211_IOC_WME_CWMAX:           /* WME: CWmax */
 2394         case IEEE80211_IOC_WME_AIFS:            /* WME: AIFS */
 2395         case IEEE80211_IOC_WME_TXOPLIMIT:       /* WME: txops limit */
 2396         case IEEE80211_IOC_WME_ACM:             /* WME: ACM (bss only) */
 2397         case IEEE80211_IOC_WME_ACKPOLICY:       /* WME: ACK policy (bss only) */
 2398                 error = ieee80211_ioctl_setwmeparam(ic, ireq);
 2399                 break;
 2400         case IEEE80211_IOC_DTIM_PERIOD:
 2401                 if (ic->ic_opmode != IEEE80211_M_HOSTAP &&
 2402                     ic->ic_opmode != IEEE80211_M_IBSS)
 2403                         return EINVAL;
 2404                 if (IEEE80211_DTIM_MIN <= ireq->i_val &&
 2405                     ireq->i_val <= IEEE80211_DTIM_MAX) {
 2406                         ic->ic_dtim_period = ireq->i_val;
 2407                         error = ENETRESET;              /* requires restart */
 2408                 } else
 2409                         error = EINVAL;
 2410                 break;
 2411         case IEEE80211_IOC_BEACON_INTERVAL:
 2412                 if (ic->ic_opmode != IEEE80211_M_HOSTAP &&
 2413                     ic->ic_opmode != IEEE80211_M_IBSS)
 2414                         return EINVAL;
 2415                 if (IEEE80211_BINTVAL_MIN <= ireq->i_val &&
 2416                     ireq->i_val <= IEEE80211_BINTVAL_MAX) {
 2417                         ic->ic_bintval = ireq->i_val;
 2418                         error = ENETRESET;              /* requires restart */
 2419                 } else
 2420                         error = EINVAL;
 2421                 break;
 2422         case IEEE80211_IOC_PUREG:
 2423                 if (ireq->i_val)
 2424                         ic->ic_flags |= IEEE80211_F_PUREG;
 2425                 else
 2426                         ic->ic_flags &= ~IEEE80211_F_PUREG;
 2427                 /* NB: reset only if we're operating on an 11g channel */
 2428                 if (ic->ic_curmode == IEEE80211_MODE_11G)
 2429                         error = ENETRESET;
 2430                 break;
 2431         case IEEE80211_IOC_MCAST_RATE:
 2432                 ic->ic_mcast_rate = ireq->i_val & IEEE80211_RATE_VAL;
 2433                 break;
 2434         case IEEE80211_IOC_FRAGTHRESHOLD:
 2435                 if ((ic->ic_caps & IEEE80211_C_TXFRAG) == 0 &&
 2436                     ireq->i_val != IEEE80211_FRAG_MAX)
 2437                         return EINVAL;
 2438                 if (!(IEEE80211_FRAG_MIN <= ireq->i_val &&
 2439                       ireq->i_val <= IEEE80211_FRAG_MAX))
 2440                         return EINVAL;
 2441                 ic->ic_fragthreshold = ireq->i_val;
 2442                 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
 2443                 break;
 2444         case IEEE80211_IOC_BURST:
 2445                 if (ireq->i_val) {
 2446                         if ((ic->ic_caps & IEEE80211_C_BURST) == 0)
 2447                                 return EINVAL;
 2448                         ic->ic_flags |= IEEE80211_F_BURST;
 2449                 } else
 2450                         ic->ic_flags &= ~IEEE80211_F_BURST;
 2451                 error = ENETRESET;              /* XXX maybe not for station? */
 2452                 break;
 2453         default:
 2454                 error = EINVAL;
 2455                 break;
 2456         }
 2457         if (error == ENETRESET && !IS_UP_AUTO(ic))
 2458                 error = 0;
 2459         return error;
 2460 }
 2461 
 2462 int
 2463 ieee80211_ioctl(struct ieee80211com *ic, u_long cmd, caddr_t data)
 2464 {
 2465         struct ifnet *ifp = ic->ic_ifp;
 2466         int error = 0;
 2467         struct ifreq *ifr;
 2468         struct ifaddr *ifa;                     /* XXX */
 2469 
 2470         switch (cmd) {
 2471         case SIOCSIFMEDIA:
 2472         case SIOCGIFMEDIA:
 2473                 error = ifmedia_ioctl(ifp, (struct ifreq *) data,
 2474                                 &ic->ic_media, cmd);
 2475                 break;
 2476         case SIOCG80211:
 2477                 error = ieee80211_ioctl_get80211(ic, cmd,
 2478                                 (struct ieee80211req *) data);
 2479                 break;
 2480         case SIOCS80211:
 2481                 error = suser(curthread);
 2482                 if (error == 0)
 2483                         error = ieee80211_ioctl_set80211(ic, cmd,
 2484                                         (struct ieee80211req *) data);
 2485                 break;
 2486         case SIOCGIFGENERIC:
 2487                 error = ieee80211_cfgget(ic, cmd, data);
 2488                 break;
 2489         case SIOCSIFGENERIC:
 2490                 error = suser(curthread);
 2491                 if (error)
 2492                         break;
 2493                 error = ieee80211_cfgset(ic, cmd, data);
 2494                 break;
 2495         case SIOCG80211STATS:
 2496                 ifr = (struct ifreq *)data;
 2497                 copyout(&ic->ic_stats, ifr->ifr_data, sizeof (ic->ic_stats));
 2498                 break;
 2499         case SIOCSIFMTU:
 2500                 ifr = (struct ifreq *)data;
 2501                 if (!(IEEE80211_MTU_MIN <= ifr->ifr_mtu &&
 2502                     ifr->ifr_mtu <= IEEE80211_MTU_MAX))
 2503                         error = EINVAL;
 2504                 else
 2505                         ifp->if_mtu = ifr->ifr_mtu;
 2506                 break;
 2507         case SIOCSIFADDR:
 2508                 /*
 2509                  * XXX Handle this directly so we can supress if_init calls.
 2510                  * XXX This should be done in ether_ioctl but for the moment
 2511                  * XXX there are too many other parts of the system that
 2512                  * XXX set IFF_UP and so supress if_init being called when
 2513                  * XXX it should be.
 2514                  */
 2515                 ifa = (struct ifaddr *) data;
 2516                 switch (ifa->ifa_addr->sa_family) {
 2517 #ifdef INET
 2518                 case AF_INET:
 2519                         if ((ifp->if_flags & IFF_UP) == 0) {
 2520                                 ifp->if_flags |= IFF_UP;
 2521                                 ifp->if_init(ifp->if_softc);
 2522                         }
 2523                         arp_ifinit(ifp, ifa);
 2524                         break;
 2525 #endif
 2526 #ifdef IPX
 2527                 /*
 2528                  * XXX - This code is probably wrong,
 2529                  *       but has been copied many times.
 2530                  */
 2531                 case AF_IPX: {
 2532                         struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr);
 2533 
 2534                         if (ipx_nullhost(*ina))
 2535                                 ina->x_host = *(union ipx_host *)
 2536                                     IFP2ENADDR(ifp);
 2537                         else
 2538                                 bcopy((caddr_t) ina->x_host.c_host,
 2539                                       (caddr_t) IFP2ENADDR(ifp),
 2540                                       ETHER_ADDR_LEN);
 2541                         /* fall thru... */
 2542                 }
 2543 #endif
 2544                 default:
 2545                         if ((ifp->if_flags & IFF_UP) == 0) {
 2546                                 ifp->if_flags |= IFF_UP;
 2547                                 ifp->if_init(ifp->if_softc);
 2548                         }
 2549                         break;
 2550                 }
 2551                 break;
 2552         default:
 2553                 error = ether_ioctl(ifp, cmd, data);
 2554                 break;
 2555         }
 2556         return error;
 2557 }

Cache object: 1e8220d4fd2e8a93ed100eb274cebf09


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.