diff options
Diffstat (limited to 'sys/net80211/ieee80211_power.c')
-rw-r--r-- | sys/net80211/ieee80211_power.c | 239 |
1 files changed, 138 insertions, 101 deletions
diff --git a/sys/net80211/ieee80211_power.c b/sys/net80211/ieee80211_power.c index e764e1f..2a7dda8 100644 --- a/sys/net80211/ieee80211_power.c +++ b/sys/net80211/ieee80211_power.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2002-2007 Sam Leffler, Errno Consulting + * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,6 +29,8 @@ __FBSDID("$FreeBSD$"); /* * IEEE 802.11 power save support. */ +#include "opt_wlan.h" + #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> @@ -43,43 +45,57 @@ __FBSDID("$FreeBSD$"); #include <net/bpf.h> -static void ieee80211_set_tim(struct ieee80211_node *ni, int set); +static void ieee80211_update_ps(struct ieee80211vap *, int); +static int ieee80211_set_tim(struct ieee80211_node *, int); + +MALLOC_DEFINE(M_80211_POWER, "80211power", "802.11 power save state"); void ieee80211_power_attach(struct ieee80211com *ic) { - if (ic->ic_opmode == IEEE80211_M_HOSTAP || - ic->ic_opmode == IEEE80211_M_IBSS) { +} + +void +ieee80211_power_detach(struct ieee80211com *ic) +{ +} + +void +ieee80211_power_vattach(struct ieee80211vap *vap) +{ + if (vap->iv_opmode == IEEE80211_M_HOSTAP || + vap->iv_opmode == IEEE80211_M_IBSS) { /* NB: driver should override */ - ic->ic_set_tim = ieee80211_set_tim; + vap->iv_update_ps = ieee80211_update_ps; + vap->iv_set_tim = ieee80211_set_tim; } } void -ieee80211_power_lateattach(struct ieee80211com *ic) +ieee80211_power_latevattach(struct ieee80211vap *vap) { /* * Allocate these only if needed. Beware that we * know adhoc mode doesn't support ATIM yet... */ - if (ic->ic_opmode == IEEE80211_M_HOSTAP) { - ic->ic_tim_len = howmany(ic->ic_max_aid,8) * sizeof(uint8_t); - MALLOC(ic->ic_tim_bitmap, uint8_t *, ic->ic_tim_len, - M_DEVBUF, M_NOWAIT | M_ZERO); - if (ic->ic_tim_bitmap == NULL) { + if (vap->iv_opmode == IEEE80211_M_HOSTAP) { + vap->iv_tim_len = howmany(vap->iv_max_aid,8) * sizeof(uint8_t); + MALLOC(vap->iv_tim_bitmap, uint8_t *, vap->iv_tim_len, + M_80211_POWER, M_NOWAIT | M_ZERO); + if (vap->iv_tim_bitmap == NULL) { printf("%s: no memory for TIM bitmap!\n", __func__); /* XXX good enough to keep from crashing? */ - ic->ic_tim_len = 0; + vap->iv_tim_len = 0; } } } void -ieee80211_power_detach(struct ieee80211com *ic) +ieee80211_power_vdetach(struct ieee80211vap *vap) { - if (ic->ic_tim_bitmap != NULL) { - FREE(ic->ic_tim_bitmap, M_DEVBUF); - ic->ic_tim_bitmap = NULL; + if (vap->iv_tim_bitmap != NULL) { + FREE(vap->iv_tim_bitmap, M_80211_POWER); + vap->iv_tim_bitmap = NULL; } } @@ -116,12 +132,16 @@ ieee80211_node_saveq_age(struct ieee80211_node *ni) int discard = 0; if (IEEE80211_NODE_SAVEQ_QLEN(ni) != 0) { +#ifdef IEEE80211_DEBUG + struct ieee80211vap *vap = ni->ni_vap; +#endif struct mbuf *m; IEEE80211_NODE_SAVEQ_LOCK(ni); while (IF_POLL(&ni->ni_savedq, m) != NULL && M_AGE_GET(m) < IEEE80211_INACT_WAIT) { -IEEE80211_DPRINTF(ni->ni_ic, IEEE80211_MSG_POWER, "[%s] discard frame, age %u\n", ether_sprintf(ni->ni_macaddr), M_AGE_GET(m));/*XXX*/ + IEEE80211_NOTE(vap, IEEE80211_MSG_POWER, ni, + "discard frame, age %u", M_AGE_GET(m)); _IEEE80211_NODE_SAVEQ_DEQUEUE_HEAD(ni, m); m_freem(m); discard++; @@ -130,7 +150,7 @@ IEEE80211_DPRINTF(ni->ni_ic, IEEE80211_MSG_POWER, "[%s] discard frame, age %u\n" M_AGE_SUB(m, IEEE80211_INACT_WAIT); IEEE80211_NODE_SAVEQ_UNLOCK(ni); - IEEE80211_NOTE(ni->ni_ic, IEEE80211_MSG_POWER, ni, + IEEE80211_NOTE(vap, IEEE80211_MSG_POWER, ni, "discard %u frames for age", discard); IEEE80211_NODE_STAT_ADD(ni, ps_discard, discard); } @@ -138,35 +158,52 @@ IEEE80211_DPRINTF(ni->ni_ic, IEEE80211_MSG_POWER, "[%s] discard frame, age %u\n" } /* - * Indicate whether there are frames queued for a station in power-save mode. + * Handle a change in the PS station occupancy. */ static void +ieee80211_update_ps(struct ieee80211vap *vap, int nsta) +{ + + KASSERT(vap->iv_opmode == IEEE80211_M_HOSTAP || + vap->iv_opmode == IEEE80211_M_IBSS, + ("operating mode %u", vap->iv_opmode)); +} + +/* + * Indicate whether there are frames queued for a station in power-save mode. + */ +static int ieee80211_set_tim(struct ieee80211_node *ni, int set) { + struct ieee80211vap *vap = ni->ni_vap; struct ieee80211com *ic = ni->ni_ic; uint16_t aid; + int changed; - KASSERT(ic->ic_opmode == IEEE80211_M_HOSTAP || - ic->ic_opmode == IEEE80211_M_IBSS, - ("operating mode %u", ic->ic_opmode)); + KASSERT(vap->iv_opmode == IEEE80211_M_HOSTAP || + vap->iv_opmode == IEEE80211_M_IBSS, + ("operating mode %u", vap->iv_opmode)); aid = IEEE80211_AID(ni->ni_associd); - KASSERT(aid < ic->ic_max_aid, - ("bogus aid %u, max %u", aid, ic->ic_max_aid)); + KASSERT(aid < vap->iv_max_aid, + ("bogus aid %u, max %u", aid, vap->iv_max_aid)); - IEEE80211_BEACON_LOCK(ic); - if (set != (isset(ic->ic_tim_bitmap, aid) != 0)) { + IEEE80211_LOCK(ic); + changed = (set != (isset(vap->iv_tim_bitmap, aid) != 0)); + if (changed) { if (set) { - setbit(ic->ic_tim_bitmap, aid); - ic->ic_ps_pending++; + setbit(vap->iv_tim_bitmap, aid); + vap->iv_ps_pending++; } else { - clrbit(ic->ic_tim_bitmap, aid); - ic->ic_ps_pending--; + clrbit(vap->iv_tim_bitmap, aid); + vap->iv_ps_pending--; } - /* NB: we know ic is in RUN state so no need to check */ - ic->ic_update_beacon(ic, IEEE80211_BEACON_TIM); + /* NB: we know vap is in RUN state so no need to check */ + vap->iv_update_beacon(vap, IEEE80211_BEACON_TIM); } - IEEE80211_BEACON_UNLOCK(ic); + IEEE80211_UNLOCK(ic); + + return changed; } /* @@ -177,6 +214,7 @@ ieee80211_set_tim(struct ieee80211_node *ni, int set) void ieee80211_pwrsave(struct ieee80211_node *ni, struct mbuf *m) { + struct ieee80211vap *vap = ni->ni_vap; struct ieee80211com *ic = ni->ni_ic; int qlen, age; @@ -184,13 +222,13 @@ ieee80211_pwrsave(struct ieee80211_node *ni, struct mbuf *m) if (_IF_QFULL(&ni->ni_savedq)) { _IF_DROP(&ni->ni_savedq); IEEE80211_NODE_SAVEQ_UNLOCK(ni); - IEEE80211_DPRINTF(ic, IEEE80211_MSG_ANY, - "[%s] pwr save q overflow, drops %d (size %d)\n", - ether_sprintf(ni->ni_macaddr), - ni->ni_savedq.ifq_drops, IEEE80211_PS_MAX_QUEUE); + IEEE80211_NOTE(vap, IEEE80211_MSG_ANY, ni, + "pwr save q overflow, drops %d (size %d)", + ni->ni_savedq.ifq_drops, IEEE80211_PS_MAX_QUEUE); #ifdef IEEE80211_DEBUG - if (ieee80211_msg_dumppkts(ic)) - ieee80211_dump_pkt(ic, mtod(m, caddr_t), m->m_len, -1, -1); + if (ieee80211_msg_dumppkts(vap)) + ieee80211_dump_pkt(ni->ni_ic, mtod(m, caddr_t), + m->m_len, -1, -1); #endif m_freem(m); return; @@ -207,57 +245,26 @@ ieee80211_pwrsave(struct ieee80211_node *ni, struct mbuf *m) _IEEE80211_NODE_SAVEQ_ENQUEUE(ni, m, qlen, age); IEEE80211_NODE_SAVEQ_UNLOCK(ni); - IEEE80211_DPRINTF(ic, IEEE80211_MSG_POWER, - "[%s] save frame with age %d, %u now queued\n", - ether_sprintf(ni->ni_macaddr), age, qlen); + IEEE80211_NOTE(vap, IEEE80211_MSG_POWER, ni, + "save frame with age %d, %u now queued", age, qlen); - if (qlen == 1 && ic->ic_set_tim != NULL) - ic->ic_set_tim(ni, 1); + if (qlen == 1 && vap->iv_set_tim != NULL) + vap->iv_set_tim(ni, 1); } /* - * Handle station power-save state change. + * Unload the frames from the ps q but don't send them + * to the driver yet. We do this in two stages to minimize + * locking but also because there's no easy way to preserve + * ordering given the existing ifnet access mechanisms. + * XXX could be optimized */ -void -ieee80211_node_pwrsave(struct ieee80211_node *ni, int enable) +static void +pwrsave_flushq(struct ieee80211_node *ni) { - struct ieee80211com *ic = ni->ni_ic; struct mbuf *m, *mhead, *mtail; int mcount; - if (enable) { - if ((ni->ni_flags & IEEE80211_NODE_PWR_MGT) == 0) - ic->ic_ps_sta++; - ni->ni_flags |= IEEE80211_NODE_PWR_MGT; - IEEE80211_NOTE(ic, IEEE80211_MSG_POWER, ni, - "power save mode on, %u sta's in ps mode", ic->ic_ps_sta); - return; - } - - if (ni->ni_flags & IEEE80211_NODE_PWR_MGT) - ic->ic_ps_sta--; - ni->ni_flags &= ~IEEE80211_NODE_PWR_MGT; - IEEE80211_NOTE(ic, IEEE80211_MSG_POWER, ni, - "power save mode off, %u sta's in ps mode", ic->ic_ps_sta); - /* XXX if no stations in ps mode, flush mc frames */ - - /* - * Flush queued unicast frames. - */ - if (IEEE80211_NODE_SAVEQ_QLEN(ni) == 0) { - if (ic->ic_set_tim != NULL) - ic->ic_set_tim(ni, 0); /* just in case */ - return; - } - IEEE80211_NOTE(ic, IEEE80211_MSG_POWER, ni, - "flush ps queue, %u packets queue", IEEE80211_NODE_SAVEQ_QLEN(ni)); - /* - * Unload the frames from the ps q but don't send them - * to the driver yet. We do this in two stages to minimize - * locking but also because there's no easy way to preserve - * ordering given the existing ifnet access mechanisms. - * XXX could be optimized - */ IEEE80211_NODE_SAVEQ_LOCK(ni); mcount = IEEE80211_NODE_SAVEQ_QLEN(ni); mhead = mtail = NULL; @@ -275,26 +282,67 @@ ieee80211_node_pwrsave(struct ieee80211_node *ni, int enable) IEEE80211_NODE_SAVEQ_UNLOCK(ni); if (mhead != NULL) { /* XXX need different driver interface */ - /* XXX bypasses q max */ - IF_PREPEND_LIST(&ic->ic_ifp->if_snd, mhead, mtail, mcount); + /* XXX bypasses q max and OACTIVE */ + struct ifnet *ifp = ni->ni_vap->iv_ifp; + IF_PREPEND_LIST(&ifp->if_snd, mhead, mtail, mcount); + if_start(ifp); + } +} + +/* + * Handle station power-save state change. + */ +void +ieee80211_node_pwrsave(struct ieee80211_node *ni, int enable) +{ + struct ieee80211vap *vap = ni->ni_vap; + int update; + + update = 0; + if (enable) { + if ((ni->ni_flags & IEEE80211_NODE_PWR_MGT) == 0) { + vap->iv_ps_sta++; + update = 1; + } + ni->ni_flags |= IEEE80211_NODE_PWR_MGT; + IEEE80211_NOTE(vap, IEEE80211_MSG_POWER, ni, + "power save mode on, %u sta's in ps mode", vap->iv_ps_sta); + + if (update) + vap->iv_update_ps(vap, vap->iv_ps_sta); + } else { + if (ni->ni_flags & IEEE80211_NODE_PWR_MGT) { + vap->iv_ps_sta--; + update = 1; + } + ni->ni_flags &= ~IEEE80211_NODE_PWR_MGT; + IEEE80211_NOTE(vap, IEEE80211_MSG_POWER, ni, + "power save mode off, %u sta's in ps mode", vap->iv_ps_sta); + + /* NB: order here is intentional so TIM is clear before flush */ + if (vap->iv_set_tim != NULL) + vap->iv_set_tim(ni, 0); + if (update) { + /* NB if no sta's in ps, driver should flush mc q */ + vap->iv_update_ps(vap, vap->iv_ps_sta); + } + pwrsave_flushq(ni); } - if (ic->ic_set_tim != NULL) - ic->ic_set_tim(ni, 0); } /* * Handle power-save state change in station mode. */ void -ieee80211_sta_pwrsave(struct ieee80211com *ic, int enable) +ieee80211_sta_pwrsave(struct ieee80211vap *vap, int enable) { - struct ieee80211_node *ni = ic->ic_bss; + struct ieee80211_node *ni = vap->iv_bss; int qlen; if (!((enable != 0) ^ ((ni->ni_flags & IEEE80211_NODE_PWR_MGT) != 0))) return; - IEEE80211_NOTE(ic, IEEE80211_MSG_POWER, ni, + IEEE80211_NOTE(vap, IEEE80211_MSG_POWER, ni, "sta power save mode %s", enable ? "on" : "off"); if (!enable) { ni->ni_flags &= ~IEEE80211_NODE_PWR_MGT; @@ -307,20 +355,9 @@ ieee80211_sta_pwrsave(struct ieee80211com *ic, int enable) */ qlen = IEEE80211_NODE_SAVEQ_QLEN(ni); if (qlen != 0) { - IEEE80211_NOTE(ic, IEEE80211_MSG_POWER, ni, + IEEE80211_NOTE(vap, IEEE80211_MSG_POWER, ni, "flush ps queue, %u packets queued", qlen); - for (;;) { - struct mbuf *m; - - IEEE80211_NODE_SAVEQ_LOCK(ni); - _IEEE80211_NODE_SAVEQ_DEQUEUE_HEAD(ni, m); - IEEE80211_NODE_SAVEQ_UNLOCK(ni); - if (m == NULL) - break; - /* XXX need different driver interface */ - /* XXX bypasses q max */ - IF_ENQUEUE(&ic->ic_ifp->if_snd, m); - } + pwrsave_flushq(ni); } } else { ni->ni_flags |= IEEE80211_NODE_PWR_MGT; |