ieee80211_output.c revision 121174
1/*- 2 * Copyright (c) 2001 Atsushi Onoe 3 * Copyright (c) 2002, 2003 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: head/sys/net80211/ieee80211_output.c 121174 2003-10-17 21:54:59Z sam $"); 35 36#include "opt_inet.h" 37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/mbuf.h> 41#include <sys/malloc.h> 42#include <sys/kernel.h> 43#include <sys/socket.h> 44#include <sys/sockio.h> 45#include <sys/endian.h> 46#include <sys/errno.h> 47#include <sys/bus.h> 48#include <sys/proc.h> 49#include <sys/sysctl.h> 50 51#include <machine/atomic.h> 52 53#include <net/if.h> 54#include <net/if_dl.h> 55#include <net/if_media.h> 56#include <net/if_arp.h> 57#include <net/ethernet.h> 58#include <net/if_llc.h> 59 60#include <net80211/ieee80211_var.h> 61 62#include <net/bpf.h> 63 64#ifdef INET 65#include <netinet/in.h> 66#include <netinet/if_ether.h> 67#endif 68 69/* 70 * Send a management frame to the specified node. The node pointer 71 * must have a reference as the pointer will be passed to the driver 72 * and potentially held for a long time. If the frame is successfully 73 * dispatched to the driver, then it is responsible for freeing the 74 * reference (and potentially free'ing up any associated storage). 75 */ 76static int 77ieee80211_mgmt_output(struct ifnet *ifp, struct ieee80211_node *ni, 78 struct mbuf *m, int type) 79{ 80 struct ieee80211com *ic = (void *)ifp; 81 struct ieee80211_frame *wh; 82 83 KASSERT(ni != NULL, ("null node")); 84 ni->ni_inact = 0; 85 86 /* 87 * Yech, hack alert! We want to pass the node down to the 88 * driver's start routine. If we don't do so then the start 89 * routine must immediately look it up again and that can 90 * cause a lock order reversal if, for example, this frame 91 * is being sent because the station is being timedout and 92 * the frame being sent is a DEAUTH message. We could stick 93 * this in an m_tag and tack that on to the mbuf. However 94 * that's rather expensive to do for every frame so instead 95 * we stuff it in the rcvif field since outbound frames do 96 * not (presently) use this. 97 */ 98 M_PREPEND(m, sizeof(struct ieee80211_frame), M_DONTWAIT); 99 if (m == NULL) 100 return ENOMEM; 101 KASSERT(m->m_pkthdr.rcvif == NULL, ("rcvif not null")); 102 m->m_pkthdr.rcvif = (void *)ni; 103 104 wh = mtod(m, struct ieee80211_frame *); 105 wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT | type; 106 wh->i_fc[1] = IEEE80211_FC1_DIR_NODS; 107 *(u_int16_t *)wh->i_dur = 0; 108 *(u_int16_t *)wh->i_seq = 109 htole16(ni->ni_txseq << IEEE80211_SEQ_SEQ_SHIFT); 110 ni->ni_txseq++; 111 IEEE80211_ADDR_COPY(wh->i_addr1, ni->ni_macaddr); 112 IEEE80211_ADDR_COPY(wh->i_addr2, ic->ic_myaddr); 113 IEEE80211_ADDR_COPY(wh->i_addr3, ni->ni_bssid); 114 115 if (ifp->if_flags & IFF_DEBUG) { 116 /* avoid to print too many frames */ 117 if (ic->ic_opmode == IEEE80211_M_IBSS || 118#ifdef IEEE80211_DEBUG 119 ieee80211_debug > 1 || 120#endif 121 (type & IEEE80211_FC0_SUBTYPE_MASK) != 122 IEEE80211_FC0_SUBTYPE_PROBE_RESP) 123 if_printf(ifp, "sending %s to %s on channel %u\n", 124 ieee80211_mgt_subtype_name[ 125 (type & IEEE80211_FC0_SUBTYPE_MASK) 126 >> IEEE80211_FC0_SUBTYPE_SHIFT], 127 ether_sprintf(ni->ni_macaddr), 128 ieee80211_chan2ieee(ic, ni->ni_chan)); 129 } 130 131 IF_ENQUEUE(&ic->ic_mgtq, m); 132 ifp->if_timer = 1; 133 (*ifp->if_start)(ifp); 134 return 0; 135} 136 137/* 138 * Encapsulate an outbound data frame. The mbuf chain is updated and 139 * a reference to the destination node is returned. If an error is 140 * encountered NULL is returned and the node reference will also be NULL. 141 * 142 * NB: The caller is responsible for free'ing a returned node reference. 143 * The convention is ic_bss is not reference counted; the caller must 144 * maintain that. 145 */ 146struct mbuf * 147ieee80211_encap(struct ifnet *ifp, struct mbuf *m, struct ieee80211_node **pni) 148{ 149 struct ieee80211com *ic = (void *)ifp; 150 struct ether_header eh; 151 struct ieee80211_frame *wh; 152 struct ieee80211_node *ni = NULL; 153 struct llc *llc; 154 155 if (m->m_len < sizeof(struct ether_header)) { 156 m = m_pullup(m, sizeof(struct ether_header)); 157 if (m == NULL) { 158 /* XXX statistic */ 159 goto bad; 160 } 161 } 162 memcpy(&eh, mtod(m, caddr_t), sizeof(struct ether_header)); 163 164 if (ic->ic_opmode != IEEE80211_M_STA) { 165 ni = ieee80211_find_node(ic, eh.ether_dhost); 166 if (ni == NULL) { 167 /* 168 * When not in station mode the destination 169 * address should always be in the node table 170 * if the device sends management frames to us; 171 * unless this is a multicast/broadcast frame. 172 * For devices that don't send management frames 173 * to the host we have to cheat; use the bss 174 * node instead; the card will/should clobber 175 * the bssid address as necessary. 176 * 177 * XXX this handles AHDEMO because all devices 178 * that support it don't send mgmt frames; 179 * but it might be better to test explicitly 180 */ 181 if (!IEEE80211_IS_MULTICAST(eh.ether_dhost) && 182 (ic->ic_caps & IEEE80211_C_RCVMGT)) { 183 IEEE80211_DPRINTF(("%s: no node for dst %s, " 184 "discard frame\n", __func__, 185 ether_sprintf(eh.ether_dhost))); 186 goto bad; 187 } 188 ni = ic->ic_bss; 189 } 190 } else 191 ni = ic->ic_bss; 192 ni->ni_inact = 0; 193 194 m_adj(m, sizeof(struct ether_header) - sizeof(struct llc)); 195 llc = mtod(m, struct llc *); 196 llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP; 197 llc->llc_control = LLC_UI; 198 llc->llc_snap.org_code[0] = 0; 199 llc->llc_snap.org_code[1] = 0; 200 llc->llc_snap.org_code[2] = 0; 201 llc->llc_snap.ether_type = eh.ether_type; 202 M_PREPEND(m, sizeof(struct ieee80211_frame), M_DONTWAIT); 203 if (m == NULL) 204 goto bad; 205 wh = mtod(m, struct ieee80211_frame *); 206 wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_DATA; 207 *(u_int16_t *)wh->i_dur = 0; 208 *(u_int16_t *)wh->i_seq = 209 htole16(ni->ni_txseq << IEEE80211_SEQ_SEQ_SHIFT); 210 ni->ni_txseq++; 211 switch (ic->ic_opmode) { 212 case IEEE80211_M_STA: 213 wh->i_fc[1] = IEEE80211_FC1_DIR_TODS; 214 IEEE80211_ADDR_COPY(wh->i_addr1, ni->ni_bssid); 215 IEEE80211_ADDR_COPY(wh->i_addr2, eh.ether_shost); 216 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_dhost); 217 break; 218 case IEEE80211_M_IBSS: 219 case IEEE80211_M_AHDEMO: 220 wh->i_fc[1] = IEEE80211_FC1_DIR_NODS; 221 IEEE80211_ADDR_COPY(wh->i_addr1, eh.ether_dhost); 222 IEEE80211_ADDR_COPY(wh->i_addr2, eh.ether_shost); 223 IEEE80211_ADDR_COPY(wh->i_addr3, ni->ni_bssid); 224 break; 225 case IEEE80211_M_HOSTAP: 226 wh->i_fc[1] = IEEE80211_FC1_DIR_FROMDS; 227 IEEE80211_ADDR_COPY(wh->i_addr1, eh.ether_dhost); 228 IEEE80211_ADDR_COPY(wh->i_addr2, ni->ni_bssid); 229 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_shost); 230 break; 231 case IEEE80211_M_MONITOR: 232 goto bad; 233 } 234 *pni = ni; 235 return m; 236bad: 237 if (m != NULL) 238 m_freem(m); 239 if (ni && ni != ic->ic_bss) 240 ieee80211_free_node(ic, ni); 241 *pni = NULL; 242 return NULL; 243} 244 245/* 246 * Add a supported rates element id to a frame. 247 */ 248u_int8_t * 249ieee80211_add_rates(u_int8_t *frm, const struct ieee80211_rateset *rs) 250{ 251 int nrates; 252 253 *frm++ = IEEE80211_ELEMID_RATES; 254 nrates = rs->rs_nrates; 255 if (nrates > IEEE80211_RATE_SIZE) 256 nrates = IEEE80211_RATE_SIZE; 257 *frm++ = nrates; 258 memcpy(frm, rs->rs_rates, nrates); 259 return frm + nrates; 260} 261 262/* 263 * Add an extended supported rates element id to a frame. 264 */ 265u_int8_t * 266ieee80211_add_xrates(u_int8_t *frm, const struct ieee80211_rateset *rs) 267{ 268 /* 269 * Add an extended supported rates element if operating in 11g mode. 270 */ 271 if (rs->rs_nrates > IEEE80211_RATE_SIZE) { 272 int nrates = rs->rs_nrates - IEEE80211_RATE_SIZE; 273 *frm++ = IEEE80211_ELEMID_XRATES; 274 *frm++ = nrates; 275 memcpy(frm, rs->rs_rates + IEEE80211_RATE_SIZE, nrates); 276 frm += nrates; 277 } 278 return frm; 279} 280 281/* 282 * Add an ssid elemet to a frame. 283 */ 284static u_int8_t * 285ieee80211_add_ssid(u_int8_t *frm, const u_int8_t *ssid, u_int len) 286{ 287 *frm++ = IEEE80211_ELEMID_SSID; 288 *frm++ = len; 289 memcpy(frm, ssid, len); 290 return frm + len; 291} 292 293static struct mbuf * 294ieee80211_getmbuf(int flags, int type, u_int pktlen) 295{ 296 struct mbuf *m; 297 298 KASSERT(pktlen <= MCLBYTES, ("802.11 packet too large: %u", pktlen)); 299 if (pktlen <= MHLEN) 300 MGETHDR(m, flags, type); 301 else 302 m = m_getcl(flags, type, M_PKTHDR); 303 return m; 304} 305 306/* 307 * Send a management frame. The node is for the destination (or ic_bss 308 * when in station mode). Nodes other than ic_bss have their reference 309 * count bumped to reflect our use for an indeterminant time. 310 */ 311int 312ieee80211_send_mgmt(struct ieee80211com *ic, struct ieee80211_node *ni, 313 int type, int arg) 314{ 315#define senderr(_x) do { ret = _x; goto bad; } while (0) 316 struct ifnet *ifp = &ic->ic_if; 317 struct mbuf *m; 318 u_int8_t *frm; 319 enum ieee80211_phymode mode; 320 u_int16_t capinfo; 321 int ret, timer; 322 323 KASSERT(ni != NULL, ("null node")); 324 325 /* 326 * Hold a reference on the node so it doesn't go away until after 327 * the xmit is complete all the way in the driver. On error we 328 * will remove our reference. 329 */ 330 if (ni != ic->ic_bss) 331 ieee80211_ref_node(ni); 332 timer = 0; 333 switch (type) { 334 case IEEE80211_FC0_SUBTYPE_PROBE_REQ: 335 /* 336 * prreq frame format 337 * [tlv] ssid 338 * [tlv] supported rates 339 * [tlv] extended supported rates 340 */ 341 m = ieee80211_getmbuf(M_DONTWAIT, MT_DATA, 342 2 + ic->ic_des_esslen 343 + 2 + IEEE80211_RATE_SIZE 344 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)); 345 if (m == NULL) 346 senderr(ENOMEM); 347 m->m_data += sizeof(struct ieee80211_frame); 348 frm = mtod(m, u_int8_t *); 349 frm = ieee80211_add_ssid(frm, ic->ic_des_essid, ic->ic_des_esslen); 350 mode = ieee80211_chan2mode(ic, ni->ni_chan); 351 frm = ieee80211_add_rates(frm, &ic->ic_sup_rates[mode]); 352 frm = ieee80211_add_xrates(frm, &ic->ic_sup_rates[mode]); 353 m->m_pkthdr.len = m->m_len = frm - mtod(m, u_int8_t *); 354 355 timer = IEEE80211_TRANS_WAIT; 356 break; 357 358 case IEEE80211_FC0_SUBTYPE_PROBE_RESP: 359 /* 360 * probe response frame format 361 * [8] time stamp 362 * [2] beacon interval 363 * [2] cabability information 364 * [tlv] ssid 365 * [tlv] supported rates 366 * [tlv] parameter set (IBSS) 367 * [tlv] extended supported rates 368 */ 369 m = ieee80211_getmbuf(M_DONTWAIT, MT_DATA, 370 8 + 2 + 2 + 2 371 + 2 + ni->ni_esslen 372 + 2 + IEEE80211_RATE_SIZE 373 + 6 374 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)); 375 if (m == NULL) 376 senderr(ENOMEM); 377 m->m_data += sizeof(struct ieee80211_frame); 378 frm = mtod(m, u_int8_t *); 379 380 memset(frm, 0, 8); /* timestamp should be filled later */ 381 frm += 8; 382 *(u_int16_t *)frm = htole16(ic->ic_bss->ni_intval); 383 frm += 2; 384 if (ic->ic_opmode == IEEE80211_M_IBSS) 385 capinfo = IEEE80211_CAPINFO_IBSS; 386 else 387 capinfo = IEEE80211_CAPINFO_ESS; 388 if (ic->ic_flags & IEEE80211_F_WEPON) 389 capinfo |= IEEE80211_CAPINFO_PRIVACY; 390 if ((ic->ic_flags & IEEE80211_F_SHPREAMBLE) && 391 IEEE80211_IS_CHAN_2GHZ(ni->ni_chan)) 392 capinfo |= IEEE80211_CAPINFO_SHORT_PREAMBLE; 393 *(u_int16_t *)frm = htole16(capinfo); 394 frm += 2; 395 396 frm = ieee80211_add_ssid(frm, ic->ic_bss->ni_essid, 397 ic->ic_bss->ni_esslen); 398 frm = ieee80211_add_rates(frm, &ic->ic_bss->ni_rates); 399 400 if (ic->ic_opmode == IEEE80211_M_IBSS) { 401 *frm++ = IEEE80211_ELEMID_IBSSPARMS; 402 *frm++ = 2; 403 *frm++ = 0; *frm++ = 0; /* TODO: ATIM window */ 404 } else { /* IEEE80211_M_HOSTAP */ 405 /* TODO: TIM */ 406 *frm++ = IEEE80211_ELEMID_TIM; 407 *frm++ = 4; /* length */ 408 *frm++ = 0; /* DTIM count */ 409 *frm++ = 1; /* DTIM period */ 410 *frm++ = 0; /* bitmap control */ 411 *frm++ = 0; /* Partial Virtual Bitmap (variable length) */ 412 } 413 frm = ieee80211_add_xrates(frm, &ic->ic_bss->ni_rates); 414 m->m_pkthdr.len = m->m_len = frm - mtod(m, u_int8_t *); 415 break; 416 417 case IEEE80211_FC0_SUBTYPE_AUTH: 418 MGETHDR(m, M_DONTWAIT, MT_DATA); 419 if (m == NULL) 420 senderr(ENOMEM); 421 MH_ALIGN(m, 2 * 3); 422 m->m_pkthdr.len = m->m_len = 6; 423 frm = mtod(m, u_int8_t *); 424 /* TODO: shared key auth */ 425 ((u_int16_t *)frm)[0] = htole16(IEEE80211_AUTH_ALG_OPEN); 426 ((u_int16_t *)frm)[1] = htole16(arg); /* sequence number */ 427 ((u_int16_t *)frm)[2] = 0; /* status */ 428 if (ic->ic_opmode == IEEE80211_M_STA) 429 timer = IEEE80211_TRANS_WAIT; 430 break; 431 432 case IEEE80211_FC0_SUBTYPE_DEAUTH: 433 if (ifp->if_flags & IFF_DEBUG) 434 if_printf(ifp, "station %s deauthenticate (reason %d)\n", 435 ether_sprintf(ni->ni_macaddr), arg); 436 MGETHDR(m, M_DONTWAIT, MT_DATA); 437 if (m == NULL) 438 senderr(ENOMEM); 439 MH_ALIGN(m, 2); 440 m->m_pkthdr.len = m->m_len = 2; 441 *mtod(m, u_int16_t *) = htole16(arg); /* reason */ 442 break; 443 444 case IEEE80211_FC0_SUBTYPE_ASSOC_REQ: 445 case IEEE80211_FC0_SUBTYPE_REASSOC_REQ: 446 /* 447 * asreq frame format 448 * [2] capability information 449 * [2] listen interval 450 * [6*] current AP address (reassoc only) 451 * [tlv] ssid 452 * [tlv] supported rates 453 * [tlv] extended supported rates 454 */ 455 m = ieee80211_getmbuf(M_DONTWAIT, MT_DATA, 456 sizeof(capinfo) 457 + sizeof(u_int16_t) 458 + IEEE80211_ADDR_LEN 459 + 2 + ni->ni_esslen 460 + 2 + IEEE80211_RATE_SIZE 461 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)); 462 if (m == NULL) 463 senderr(ENOMEM); 464 m->m_data += sizeof(struct ieee80211_frame); 465 frm = mtod(m, u_int8_t *); 466 467 capinfo = 0; 468 if (ic->ic_opmode == IEEE80211_M_IBSS) 469 capinfo |= IEEE80211_CAPINFO_IBSS; 470 else /* IEEE80211_M_STA */ 471 capinfo |= IEEE80211_CAPINFO_ESS; 472 if (ic->ic_flags & IEEE80211_F_WEPON) 473 capinfo |= IEEE80211_CAPINFO_PRIVACY; 474 /* 475 * NB: Some 11a AP's reject the request when 476 * short premable is set. 477 */ 478 if ((ic->ic_flags & IEEE80211_F_SHPREAMBLE) && 479 IEEE80211_IS_CHAN_2GHZ(ni->ni_chan)) 480 capinfo |= IEEE80211_CAPINFO_SHORT_PREAMBLE; 481 if (ic->ic_flags & IEEE80211_F_SHSLOT) 482 capinfo |= IEEE80211_CAPINFO_SHORT_SLOTTIME; 483 *(u_int16_t *)frm = htole16(capinfo); 484 frm += 2; 485 486 *(u_int16_t *)frm = htole16(ic->ic_lintval); 487 frm += 2; 488 489 if (type == IEEE80211_FC0_SUBTYPE_REASSOC_REQ) { 490 IEEE80211_ADDR_COPY(frm, ic->ic_bss->ni_bssid); 491 frm += IEEE80211_ADDR_LEN; 492 } 493 494 frm = ieee80211_add_ssid(frm, ni->ni_essid, ni->ni_esslen); 495 frm = ieee80211_add_rates(frm, &ni->ni_rates); 496 frm = ieee80211_add_xrates(frm, &ni->ni_rates); 497 m->m_pkthdr.len = m->m_len = frm - mtod(m, u_int8_t *); 498 499 timer = IEEE80211_TRANS_WAIT; 500 break; 501 502 case IEEE80211_FC0_SUBTYPE_ASSOC_RESP: 503 case IEEE80211_FC0_SUBTYPE_REASSOC_RESP: 504 /* 505 * asreq frame format 506 * [2] capability information 507 * [2] status 508 * [2] association ID 509 * [tlv] supported rates 510 * [tlv] extended supported rates 511 */ 512 m = ieee80211_getmbuf(M_DONTWAIT, MT_DATA, 513 sizeof(capinfo) 514 + sizeof(u_int16_t) 515 + sizeof(u_int16_t) 516 + 2 + IEEE80211_RATE_SIZE 517 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)); 518 if (m == NULL) 519 senderr(ENOMEM); 520 m->m_data += sizeof(struct ieee80211_frame); 521 frm = mtod(m, u_int8_t *); 522 523 capinfo = IEEE80211_CAPINFO_ESS; 524 if (ic->ic_flags & IEEE80211_F_WEPON) 525 capinfo |= IEEE80211_CAPINFO_PRIVACY; 526 if ((ic->ic_flags & IEEE80211_F_SHPREAMBLE) && 527 IEEE80211_IS_CHAN_2GHZ(ni->ni_chan)) 528 capinfo |= IEEE80211_CAPINFO_SHORT_PREAMBLE; 529 *(u_int16_t *)frm = htole16(capinfo); 530 frm += 2; 531 532 *(u_int16_t *)frm = htole16(arg); /* status */ 533 frm += 2; 534 535 if (arg == IEEE80211_STATUS_SUCCESS) 536 *(u_int16_t *)frm = htole16(ni->ni_associd); 537 frm += 2; 538 539 frm = ieee80211_add_rates(frm, &ni->ni_rates); 540 frm = ieee80211_add_xrates(frm, &ni->ni_rates); 541 m->m_pkthdr.len = m->m_len = frm - mtod(m, u_int8_t *); 542 break; 543 544 case IEEE80211_FC0_SUBTYPE_DISASSOC: 545 if (ifp->if_flags & IFF_DEBUG) 546 if_printf(ifp, "station %s disassociate (reason %d)\n", 547 ether_sprintf(ni->ni_macaddr), arg); 548 MGETHDR(m, M_DONTWAIT, MT_DATA); 549 if (m == NULL) 550 senderr(ENOMEM); 551 MH_ALIGN(m, 2); 552 m->m_pkthdr.len = m->m_len = 2; 553 *mtod(m, u_int16_t *) = htole16(arg); /* reason */ 554 break; 555 556 default: 557 IEEE80211_DPRINTF(("%s: invalid mgmt frame type %u\n", 558 __func__, type)); 559 senderr(EINVAL); 560 /* NOTREACHED */ 561 } 562 563 ret = ieee80211_mgmt_output(ifp, ni, m, type); 564 if (ret == 0) { 565 if (timer) 566 ic->ic_mgt_timer = timer; 567 } else { 568bad: 569 if (ni != ic->ic_bss) /* remove ref we added */ 570 ieee80211_free_node(ic, ni); 571 } 572 return ret; 573#undef senderr 574} 575