ieee80211_release_node(ic, ni);
if (ni != NULL) ieee80211_release_node(ic, ni);
ieee80211_encap(struct ifnet *ifp, struct mbuf *m, struct ieee80211_node **pni){	struct ieee80211com *ic = (void *)ifp;	struct ether_header eh;	struct ieee80211_frame *wh;	struct ieee80211_node *ni = NULL;	struct llc *llc;	if (m->m_len < sizeof(struct ether_header)) {		m = m_pullup(m, sizeof(struct ether_header));		if (m == NULL) {			ic->ic_stats.is_tx_nombuf++;			goto bad;		}	}	memcpy(&eh, mtod(m, caddr_t), sizeof(struct ether_header));	ni = ieee80211_find_txnode(ic, eh.ether_dhost);	if (ni == NULL) {		IEEE80211_DPRINTF(("%s: no node for dst %s, discard frame\n",		    __func__, ether_sprintf(eh.ether_dhost)));		ic->ic_stats.is_tx_nonode++;		goto bad;	}	ni->ni_inact = 0;	m_adj(m, sizeof(struct ether_header) - sizeof(struct llc));	llc = mtod(m, struct llc *);	llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;	llc->llc_control = LLC_UI;	llc->llc_snap.org_code[0] = 0;	llc->llc_snap.org_code[1] = 0;	llc->llc_snap.org_code[2] = 0;	llc->llc_snap.ether_type = eh.ether_type;	M_PREPEND(m, sizeof(struct ieee80211_frame), M_DONTWAIT);	if (m == NULL) {		ic->ic_stats.is_tx_nombuf++;		goto bad;	}	wh = mtod(m, struct ieee80211_frame *);	wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_DATA;	*(u_int16_t *)&wh->i_dur[0] = 0;	*(u_int16_t *)&wh->i_seq[0] =	    htole16(ni->ni_txseq << IEEE80211_SEQ_SEQ_SHIFT);	ni->ni_txseq++;	switch (ic->ic_opmode) {	case IEEE80211_M_STA:		wh->i_fc[1] = IEEE80211_FC1_DIR_TODS;		IEEE80211_ADDR_COPY(wh->i_addr1, ni->ni_bssid);		IEEE80211_ADDR_COPY(wh->i_addr2, eh.ether_shost);		IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_dhost);		break;	case IEEE80211_M_IBSS:	case IEEE80211_M_AHDEMO:		wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;		IEEE80211_ADDR_COPY(wh->i_addr1, eh.ether_dhost);		IEEE80211_ADDR_COPY(wh->i_addr2, eh.ether_shost);		IEEE80211_ADDR_COPY(wh->i_addr3, ic->ic_bss->ni_bssid);		break;	case IEEE80211_M_HOSTAP:		wh->i_fc[1] = IEEE80211_FC1_DIR_FROMDS;		IEEE80211_ADDR_COPY(wh->i_addr1, eh.ether_dhost);		IEEE80211_ADDR_COPY(wh->i_addr2, ni->ni_bssid);		IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_shost);		break;	case IEEE80211_M_MONITOR:		goto bad;	}	if (ic->ic_flags & IEEE80211_F_WEPON)		wh->i_fc[1] |= IEEE80211_FC1_WEP;	*pni = ni;	return m;bad:	if (m != NULL)		m_freem(m);	ieee80211_release_node(ic, ni);	*pni = NULL;	return NULL;}