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