mac80211: mesh power save basics

Add routines to
- maintain a PS mode for each peer and a non-peer PS mode
- indicate own PS mode in transmitted frames
- track neighbor STAs power modes
- buffer frames when neighbors are in PS mode
- add TIM and Awake Window IE to beacons
- release frames in Mesh Peer Service Periods

Add local_pm to sta_info to represent the link-specific power
mode at this station towards the remote station. When a peer
link is established, use the default power mode stored in mesh
config. Update the PS status if the peering status of a neighbor
changes.
Maintain a mesh power mode for non-peer mesh STAs. Set the
non-peer power mode to active mode during peering. Authenticated
mesh peering is currently not working when either node is
configured to be in power save mode.

Indicate the current power mode in transmitted frames. Use QoS
Nulls to indicate mesh power mode transitions.
For performance reasons, calls to the function setting the frame
flags are placed in HWMP routing routines, as there the STA
pointer is already available.

Add peer_pm to sta_info to represent the peer's link-specific
power mode towards the local station. Add nonpeer_pm to
represent the peer's power mode towards all non-peer stations.
Track power modes based on received frames.

Add the ps_data structure to ieee80211_if_mesh (for TIM map, PS
neighbor counter and group-addressed frame buffer).

Set WLAN_STA_PS flag for STA in PS mode to use the unicast frame
buffering routines in the tx path. Update num_sta_ps to buffer
and release group-addressed frames after DTIM beacons.

Announce the awake window duration in beacons if in light or
deep sleep mode towards any peer or non-peer. Create a TIM IE
similarly to AP mode and add it to mesh beacons. Parse received
Awake Window IEs and check TIM IEs for buffered frames.

Release frames towards peers in mesh Peer Service Periods. Use
the corresponding trigger frames and monitor the MPSP status.
Append a QoS Null as trigger frame if neccessary to properly end
the MPSP. Currently, in HT channels MPSPs behave imperfectly and
show large delay spikes and frame losses.

Signed-off-by: Marco Porsch <marco@cozybit.com>
Signed-off-by: Ivan Bezyazychnyy <ivan.bezyazychnyy@gmail.com>
Signed-off-by: Mike Krinkin <krinkin.m.u@gmail.com>
Signed-off-by: Max Filippov <jcmvbkbc@gmail.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
T_offset value right after it has been updated.

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
- 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 mesh PS routines in mac80211 to keep driver
modifications minimal.

Track the beacon timing information of peers we are in PS mode
towards. Set a per-STA hrtimer which will trigger a wakeup right
before the peer's next TBTT.
Also use the same hrtimer to go to sleep mode after not
receiving a beacon in a defined time margin. In this case
calculate the next TBTT and increase the margin.

For mesh Awake Windows wakeup on SWBA (beacon_get_tim) and start
a timer which triggers a hw_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.

When enabling mesh PS, do not enable the hardware's TIM timer
interrupt.

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

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>