mac80211: free ps->bc_buf skbs on vlan device stop

When the vlan device is removed, ps->bc_buf processing can no longer
send its frames.

Signed-off-by: Michael Braun <michael-dev@fami-braun.de>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
mac80211: fix WPA with VLAN on AP side with ps-sta

When sending a broadcast while at least on of the connected stations is
sleeping, it gets queued and send after a DTIM beacon is sent.
If the packet was to be sent on a vlan interface, the vif used for dequeing
from the per-bss queue does not hold the per-vlan sdata. The correct sdata is
required to use the correct per-vlan broadcast/multicast key.

This patch fixes this by restoring the per-vlan sdata using the skb->dev entry.

Signed-off-by: Michael Braun <michael-dev@fami-braun.de>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
mac80211: consolidate MBSS change notification

A few mesh utility functions will call
ieee80211_bss_info_change_notify(), and then the caller
might notify the driver of the same change again. Avoid
this redundancy by propagating the BSS changes and
generally calling bss_info_change_notify() once per
change.

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
mac80211: cache mesh beacon

Previously, the entire mesh beacon would be generated each
time the beacon timer fired. Instead generate a beacon
head and tail (so the TIM can easily be inserted when mesh
power save is on) when starting a mesh or the MBSS
parameters change.

Also add a mutex for protecting beacon updates and
preventing leaks.

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
mac80211: generate mesh probe responses

Mesh interfaces will now respond to any broadcast (or
matching directed mesh) probe requests with a probe
response.

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
mac80211: move mesh sync beacon handler into neighbour_update

Move the beacon handler into mesh_neighbour_update where the STA
pointer is already available. This avoids additional overhead
and simplifies the handler.
The repositioning will also benefit mesh PS which uses the TSF
and the just updated T_offset value.

Rename the handler to better reflect its purpose.

Signed-off-by: Marco Porsch <marco@cozybit.com>
mac80211: mesh power save doze scheduling

Configure the HW for PS mode if the local mesh PS parameters
allow so.

Expose a callback ieee80211_mps_init for drivers to register
mesh powersave ops:
- hw_doze - put the radio to sleep now, wake up at given TBTT
- hw_wakeup - wake the radio up for frame RX
These ops may be extended in the future to allow drivers/HW to
implement mesh PS themselves. (The current design goal was to
concentrate most mesh PS routines in mac80211 to keep driver
modifications minimal.

Track the beacon timing information of peers we are in PS mode
towards. Calculate the next TBTT per STA. Stay awake to receive
multicast traffic after DTIM beacons.

When going to doze state, get the most imminent STA TBTT and
configure the driver to trigger a wakeup on time to catch that
beacon. After successful receipt put the HW to doze again.
Set a timeout for the case that the beacon is not received on
time. In this case calculate the following TBTT and go to doze
again.

For mesh Awake Windows wakeup on SWBA (beacon_get_tim) and start
a timer which triggers a doze call on expiry.

Signed-off-by: Marco Porsch <marco@cozybit.com>
ath9k: mesh powersave support

Register mesh PS ops on interface add and de-register on
removal.

React to doze/wakeup calls issued by mac80211.
Add a PS status flag PS_MAC80211_CTL to store last mesh PS
command from mac80211.

Initialize HW beacon wakeup registers.
On doze call configure the HW to wakeup on the given TSF value.

Signed-off-by: Marco Porsch <marco@cozybit.com>
mac80211: fixes for mesh powersave logic

Avoid MPSP flags getting stuck by not requesting afurther MPSP
ownership when we already are a MPSP owner.
Reliably clear MPSP flags on peering status update.

When closing a peer link, set the peer-specific power mode to
'unknown' again.

Avoid overhead when local power mode is unchanged.

Signed-off-by: Marco Porsch <marco@cozybit.com>
mac80211: mesh link automatic power mode selection

Signed-off-by: Marco Porsch <marco@cozybit.com>
mac80211: auth PS peering wip
ath9k_htc: Add support for NL80211_IFTYPE_MESH_POINT interfaces

More specifically, enable AP-style beaconing on mesh ifaces, honor
FIF_OTHER_BSS filter and change the hw capabilities to reflect mesh
support.

Also enable IEEE80211_HW_SUPPORTS_PER_STA_GTK, IEEE80211_HW_MFP_CAPABLE
and WIPHY_FLAG_IBSS_RSN.  Probably these should depend on the
capabilities of the hardware but I don't know which hardware supports
what.  But these are required for secured mesh and work fine on our
TL-WN821N

Signed-off-by: Javier Cardona <javier@cozybit.com>
ath9k_htc: mesh powersave support

Register mesh_ps_ops on mesh interface add/remove.
React to hw_doze/hw_wakeup calls from mac80211. Before going to sleep request
mac80211's status with mps_hw_doze_allow callback.
On beacon SWBA the hardware is already in Awake state, so update the drivers
state variable accordingly.

Signed-off-by: Marco Porsch <marco@cozybit.com>
carl9170: mesh powersave support

Register mesh PS ops on interface add and de-register on removal.

React to mac80211's mps_doze/mps_wakeup calls and request mac80211's status
before going to sleep state.

The device is already in Awake state after SWBA. Update the driver state
variable accordingly.

Signed-off-by: Marco Porsch <marco@cozybit.com>
mac80211_hwsim: wip

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
ath9k_htc: wip
printk, comments, wip

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
{cfg,nl,mac}80211: make peer inactivity limit accessible to userspace

For mesh power save it is useful to remove inactive peers whose beacons we
should not track anymore.
This patch allows modifiying the corresponding peer inactivity limit, to expire
peers that we have not received frames or beacons from recently. It is checked
in the mesh housekeeping routine (currently every 60 HZ).

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>