if_ath.c

来自「madwifi上的atheros无线网卡驱动源码」· C语言 代码 · 共 2,072 行 · 第 1/5 页

C
2,072 行
字号
	 */	if (ath_hal_hasdiversity(ah)) {		sc->sc_hasdiversity = 1;		ath_hal_setdiversity(ah, AH_TRUE);		sc->sc_diversity = 1;	} else {		sc->sc_hasdiversity = 0;		sc->sc_diversity = 0;		ath_hal_setdiversity(ah, AH_FALSE);	}	sc->sc_defant = ath_hal_getdefantenna(ah);	/*	 * Not all chips have the VEOL support we want to	 * use with IBSS beacons; check here for it.	 */	sc->sc_hasveol = ath_hal_hasveol(ah);       /* Interference Mitigation causes problems with recevive sensitivity        * for OFDM rates when we are in non-STA modes. We will turn this        * capability off in non-STA VAPs        */	sc->sc_hasintmit = ath_hal_hasintmit(ah);	sc->sc_useintmit = 1;	/* get mac address from hardware */	ath_hal_getmac(ah, ic->ic_myaddr);	if (sc->sc_hasbmask) {		ath_hal_getbssidmask(ah, sc->sc_bssidmask);		ATH_SET_VAP_BSSID_MASK(sc->sc_bssidmask);		ath_hal_setbssidmask(ah, sc->sc_bssidmask);	}	IEEE80211_ADDR_COPY(dev->dev_addr, ic->ic_myaddr);	/* call MI attach routine. */	ieee80211_ifattach(ic);	/* override default methods */	ic->ic_node_alloc = ath_node_alloc;	sc->sc_node_free = ic->ic_node_free;	ic->ic_node_free = ath_node_free;	ic->ic_node_getrssi = ath_node_getrssi;#ifdef ATH_SUPERG_XR	ic->ic_node_move_data = ath_node_move_data;#endif	sc->sc_node_cleanup = ic->ic_node_cleanup;	ic->ic_node_cleanup = ath_node_cleanup;	sc->sc_recv_mgmt = ic->ic_recv_mgmt;	ic->ic_recv_mgmt = ath_recv_mgmt;	ic->ic_vap_create = ath_vap_create;	ic->ic_vap_delete = ath_vap_delete;	ic->ic_scan_start = ath_scan_start;	ic->ic_scan_end = ath_scan_end;	ic->ic_set_channel = ath_set_channel;	ic->ic_set_coverageclass = ath_set_coverageclass;	ic->ic_mhz2ieee = ath_mhz2ieee;	if (register_netdev(dev)) {		printk(KERN_ERR "%s: unable to register device\n", dev->name);		goto bad3;	}	/*	 * Attach dynamic MIB vars and announce support	 * now that we have a device name with unit number.	 */	ath_dynamic_sysctl_register(sc);	ieee80211_announce(ic);	ath_announce(dev);#ifdef ATH_TX99_DIAG	printk("%s: TX99 support enabled\n", dev->name);#endif	sc->sc_invalid = 0;	if (autocreate) {		if (!strcmp(autocreate, "none"))			autocreatemode = -1;		else if (!strcmp(autocreate, "sta"))			autocreatemode = IEEE80211_M_STA;		else if (!strcmp(autocreate, "ap"))			autocreatemode = IEEE80211_M_HOSTAP;		else if (!strcmp(autocreate, "adhoc"))			autocreatemode = IEEE80211_M_IBSS;		else if (!strcmp(autocreate, "ahdemo"))			autocreatemode = IEEE80211_M_AHDEMO;		else if (!strcmp(autocreate, "wds"))			autocreatemode = IEEE80211_M_WDS;		else if (!strcmp(autocreate, "monitor"))			autocreatemode = IEEE80211_M_MONITOR;		else {			printk(KERN_INFO "Unknown autocreate mode: %s\n",				autocreate);			autocreatemode = -1;		}	}		if (autocreatemode != -1) {		rtnl_lock();		error = ieee80211_create_vap(ic, "ath%d", dev,				autocreatemode, IEEE80211_CLONE_BSSID);		rtnl_unlock();		if (error)			printk(KERN_ERR "%s: autocreation of VAP failed: %d\n",				dev->name, error);	}	return 0;bad3:	ieee80211_ifdetach(ic);	ieee80211_rate_detach(sc->sc_rc);bad2:	ath_tx_cleanup(sc);	ath_desc_free(sc);bad:	if (ah)		ath_hal_detach(ah);	ATH_TXBUF_LOCK_DESTROY(sc);	ATH_LOCK_DESTROY(sc);	sc->sc_invalid = 1;	return error;}intath_detach(struct net_device *dev){	struct ath_softc *sc = dev->priv;	struct ath_hal *ah = sc->sc_ah;	HAL_INT tmp;	DPRINTF(sc, ATH_DEBUG_ANY, "%s: flags %x\n", __func__, dev->flags);	ath_stop(dev);	ath_hal_setpower(sc->sc_ah, HAL_PM_AWAKE);	/* Flush the radar task if it's scheduled */	if (sc->sc_rtasksched == 1)		flush_scheduled_work();	sc->sc_invalid = 1;	/*	 * NB: the order of these is important:	 * o call the 802.11 layer before detaching the HAL to	 *   ensure callbacks into the driver to delete global	 *   key cache entries can be handled	 * o reclaim the tx queue data structures after calling	 *   the 802.11 layer as we'll get called back to reclaim	 *   node state and potentially want to use them	 * o to cleanup the tx queues the HAL is called, so detach	 *   it last	 * Other than that, it's straightforward...	 */	ieee80211_ifdetach(&sc->sc_ic);	ath_hal_intrset(ah, 0);		/* disable further intr's */	ath_hal_getisr(ah, &tmp);	/* clear ISR */	if(dev->irq) {		free_irq(dev->irq, dev);		dev->irq = 0;	}#ifdef ATH_TX99_DIAG	if (sc->sc_tx99 != NULL)		sc->sc_tx99->detach(sc->sc_tx99);#endif	ieee80211_rate_detach(sc->sc_rc);	ath_desc_free(sc);	ath_tx_cleanup(sc);	ath_hal_detach(ah);	kfree(sc->sc_bslot);	sc->sc_bslot = NULL;	ath_dynamic_sysctl_unregister(sc);	ATH_LOCK_DESTROY(sc);	dev->stop = NULL; /* prevent calling ath_stop again */	unregister_netdev(dev);	return 0;}static struct ieee80211vap *ath_vap_create(struct ieee80211com *ic, const char *name, int unit,	int opmode, int flags, struct net_device *mdev){	struct ath_softc *sc = ic->ic_dev->priv;	struct ath_hal *ah = sc->sc_ah;	struct net_device *dev;	struct ath_vap *avp;	struct ieee80211vap *vap;	int ic_opmode;	if (ic->ic_dev->flags & IFF_RUNNING) {		/* needs to disable hardware too */		ath_hal_intrset(ah, 0);		/* disable interrupts */		ath_draintxq(sc);		/* stop xmit side */		ath_stoprecv(sc);		/* stop recv side */	}	/* XXX ic unlocked and race against add */	switch (opmode) {	case IEEE80211_M_STA:	/* ap+sta for repeater application */		if (sc->sc_nstavaps != 0)  /* only one sta regardless */			return NULL;		if ((sc->sc_nvaps != 0) && (!(flags & IEEE80211_NO_STABEACONS)))			return NULL;   /* If using station beacons, must first up */		if (flags & IEEE80211_NO_STABEACONS) {			sc->sc_nostabeacons = 1;			ic_opmode = IEEE80211_M_HOSTAP;	/* Run with chip in AP mode */		} else 			ic_opmode = opmode;		break;	case IEEE80211_M_IBSS:		if (sc->sc_nvaps != 0)		/* only one */			return NULL;		ic_opmode = opmode;		break;	case IEEE80211_M_AHDEMO:	case IEEE80211_M_MONITOR:		if (sc->sc_nvaps != 0 && ic->ic_opmode != opmode) {			/* preserve existing mode */			ic_opmode = ic->ic_opmode;		} else			ic_opmode = opmode;		break;	case IEEE80211_M_HOSTAP:	case IEEE80211_M_WDS:		/* permit multiple ap's and/or wds links */		/* XXX sta+ap for repeater/bridge application */		if ((sc->sc_nvaps != 0) && (ic->ic_opmode == IEEE80211_M_STA))			return NULL;		/* XXX not right, beacon buffer is allocated on RUN trans */		if (opmode == IEEE80211_M_HOSTAP && STAILQ_EMPTY(&sc->sc_bbuf))			return NULL;		/*		 * XXX Not sure if this is correct when operating only		 * with WDS links.		 */		ic_opmode = IEEE80211_M_HOSTAP;		break;	default:		return NULL;	}	if (sc->sc_nvaps >= ath_maxvaps) {		printk(KERN_WARNING "too many virtual ap's (already got %d)\n", sc->sc_nvaps);		return NULL;	}	dev = alloc_etherdev(sizeof(struct ath_vap) + sc->sc_rc->arc_vap_space);	if (dev == NULL) {		/* XXX msg */		return NULL;	}		avp = dev->priv;	ieee80211_vap_setup(ic, dev, name, unit, opmode, flags);	/* override with driver methods */	vap = &avp->av_vap;	avp->av_newstate = vap->iv_newstate;	vap->iv_newstate = ath_newstate;	vap->iv_key_alloc = ath_key_alloc;	vap->iv_key_delete = ath_key_delete;	vap->iv_key_set = ath_key_set;	vap->iv_key_update_begin = ath_key_update_begin;	vap->iv_key_update_end = ath_key_update_end;#ifdef ATH_SUPERG_COMP	vap->iv_comp_set = ath_comp_set;#endif	/* Let rate control register proc entries for the VAP */	if (sc->sc_rc->ops->dynamic_proc_register)		sc->sc_rc->ops->dynamic_proc_register(vap);	/*	 * Change the interface type for monitor mode.	 */	if (opmode == IEEE80211_M_MONITOR)		dev->type = ARPHRD_IEEE80211_RADIOTAP;	if ((flags & IEEE80211_CLONE_BSSID) &&	    sc->sc_nvaps != 0 && opmode != IEEE80211_M_WDS && sc->sc_hasbmask) {		struct ieee80211vap *v;		uint64_t id_mask;		unsigned int id;				/*		 * Hardware supports the bssid mask and a unique		 * bssid was requested.  Assign a new mac address		 * and expand our bssid mask to cover the active		 * virtual ap's with distinct addresses.		 */				/* do a full search to mark all the allocated VAPs */		id_mask = 0;		TAILQ_FOREACH(v, &ic->ic_vaps, iv_next)			id_mask |= (1 << ATH_GET_VAP_ID(v->iv_myaddr));				for (id = 0; id < ath_maxvaps; id++) {			/* get the first available slot */			if ((id_mask & (1 << id)) == 0) {				ATH_SET_VAP_BSSID(vap->iv_myaddr, id);				break;			}		}	}	avp->av_bslot = -1;	STAILQ_INIT(&avp->av_mcastq.axq_q);	ATH_TXQ_LOCK_INIT(&avp->av_mcastq);	if (opmode == IEEE80211_M_HOSTAP || opmode == IEEE80211_M_IBSS) {		/*		 * Allocate beacon state for hostap/ibss.  We know		 * a buffer is available because of the check above.		 */		avp->av_bcbuf = STAILQ_FIRST(&sc->sc_bbuf);		STAILQ_REMOVE_HEAD(&sc->sc_bbuf, bf_list);		if (opmode == IEEE80211_M_HOSTAP || !sc->sc_hasveol) {			int slot;			/*			 * Assign the VAP to a beacon xmit slot.  As			 * above, this cannot fail to find one.			 */			avp->av_bslot = 0;			for (slot = 0; slot < ath_maxvaps; slot++)				if (sc->sc_bslot[slot] == NULL) {					/*					 * XXX hack, space out slots to better					 * deal with misses					 */					if (slot + 1 < ath_maxvaps &&					    sc->sc_bslot[slot+1] == NULL) {						avp->av_bslot = slot + 1;						break;					}					avp->av_bslot = slot;					/* NB: keep looking for a double slot */				}			KASSERT(sc->sc_bslot[avp->av_bslot] == NULL,				("beacon slot %u not empty?", avp->av_bslot));			sc->sc_bslot[avp->av_bslot] = vap;			sc->sc_nbcnvaps++;		}		if ((opmode == IEEE80211_M_HOSTAP) && (sc->sc_hastsfadd)) {			/*			 * Multiple VAPs are to transmit beacons and we			 * have h/w support for TSF adjusting; enable use			 * of staggered beacons.			 */			/* XXX check for beacon interval too small */			if (ath_maxvaps > 4) {				DPRINTF(sc, ATH_DEBUG_BEACON,					"Staggered beacons are not possible "					"with maxvaps set to %d.\n",					ath_maxvaps);				sc->sc_stagbeacons = 0;			} else {				sc->sc_stagbeacons = 1;			}		}		DPRINTF(sc, ATH_DEBUG_BEACON, "sc->stagbeacons %sabled\n",			(sc->sc_stagbeacons ? "en" : "dis"));	}	if (sc->sc_hastsfadd)		ath_hal_settsfadjust(sc->sc_ah, sc->sc_stagbeacons);	SET_NETDEV_DEV(dev, ATH_GET_NETDEV_DEV(mdev));	/* complete setup */	(void) ieee80211_vap_attach(vap,		ieee80211_media_change, ieee80211_media_status);	ic->ic_opmode = ic_opmode;		if (opmode != IEEE80211_M_WDS)		sc->sc_nvaps++;			if (opmode == IEEE80211_M_STA)		sc->sc_nstavaps++;	else if (opmode == IEEE80211_M_MONITOR)		sc->sc_nmonvaps++;	/*	 * Adhoc demo mode is a pseudo mode; to the HAL it's	 * just ibss mode and the driver doesn't use management	 * frames.  Other modes carry over directly to the HAL.	 */	if (ic->ic_opmode == IEEE80211_M_AHDEMO)		sc->sc_opmode = HAL_M_IBSS;	else		sc->sc_opmode = (HAL_OPMODE) ic->ic_opmode;	/* NB: compatible */#ifdef ATH_SUPERG_XR	if ( vap->iv_flags & IEEE80211_F_XR ) {		if (ath_descdma_setup(sc, &sc->sc_grppolldma, &sc->sc_grppollbuf,			"grppoll", (sc->sc_xrpollcount+1) * HAL_ANTENNA_MAX_MODE, 1) != 0)			printk("%s:grppoll Buf allocation failed \n",__func__);		if (!sc->sc_xrtxq)			sc->sc_xrtxq = ath_txq_setup(sc, HAL_TX_QUEUE_DATA, HAL_XR_DATA);		if (sc->sc_hasdiversity) {			/* Save current diversity state if user destroys XR VAP */			sc->sc_olddiversity = sc->sc_diversity;			ath_hal_setdiversity(sc->sc_ah, 0);			sc->sc_diversity = 0;		}	}#endif	if (ic->ic_dev->flags & IFF_RUNNING) {		/* restart hardware */		if (ath_startrecv(sc) != 0)	/* restart recv */			printk("%s: %s: unable to start recv logic\n",				dev->name, __func__);		if (sc->sc_beacons)			ath_beacon_config(sc, NULL);	/* restart beacons */		ath_hal_intrset(ah, sc->sc_imask);	}	return vap;}static voidath_vap_delete(struct ieee80211vap *vap)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?