mac80211: fix for mesh sync to indicate TBTT adjustment

Currently the mesh sync code checks, whether peers indicate TBTT adjustment,
but it never sets the corresponding flag itself.

By setting ifmsh->tbtt_adjusting to true, it will set the corresponding field
in the mesh configuration IE of own beacons.
This indication will be set in the current beacon. The TBTT adjustment will be
performed afterwards, affecting the next beacon. Thus, the first beacon with
stable TBTT will not indicate adjustment anymore and peers will continue
tracking the new offset.

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
{nl,cfg,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>
{nl,cfg,mac}80211: add beacon interval and DTIM period to mesh config

Moves the default mesh beacon interval and DTIM period to cfg80211 and
makes it accessible to nl80211. This enables modifying both values at
mesh runtime.
One safety check is added that keeps the DTIM counter within the allowed
limits.

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
{cfg,nl}80211: mesh power mode config parameters

Possible values for the mesh power mode are presented in the
nl80211_mesh_power_mode enumeration. These modes are active,
light sleep and deep sleep.

power_mode has been added to the mesh config structure to hold the
user-configured default mesh power mode which will be used for new
peer links.

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
Signed-off-by: Ivan Bezyazychnyy <ivan.bezyazychnyy@gmail.com>
Signed-off-by: Mike Krinkin <krinkin.m.u@gmail.com>
{cfg,nl}80211: set and get default mesh power mode

Possibilities of setting and getting mesh default power mode are
added.

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
Signed-off-by: Ivan Bezyazychnyy <ivan.bezyazychnyy@gmail.com>
Signed-off-by: Mike Krinkin <krinkin.m.u@gmail.com>
mac80211: local link-specific mesh power mode logic

According to IEEE802.11-2012 a mesh peering is always associated between
two mesh STAs. Both mesh STAs have their own mesh power mode for the
mesh peering. This power mode is called the link-specific power mode.
The local_ps_mode field has been added to sta_info structure to represent
the link-specific power mode at this station for the station represented
by this structure.

When a peer link is established, the local link-specific power mode is
set up equal to the user-configured default power mode. To allow
successful peering, 802.11s defines that the non-peer power mode is
temporarily set to active mode during peering.

The status of the local peer-specific power modes is monitored for
mesh power mode indication and for checking if the radio may be set
to doze state. The PS status is also updated if the peering status
of a neighbor changes.

According to IEEE802.11-2012 a mesh STA maintains a mesh power mode
for non-peer mesh STAs. The non-peer mesh power mode determines when
non-peer mesh STAs may send Probe Request and Mesh Peering Open Request
frames to the mesh STA.
Based on the status of the peer-specific power modes also the non-peer
power mode is set: if there is at least one link in light or deep sleep
mode, the non-peer power mode will be deep sleep mode.

To avoid frame losses when switching to a lower power state after peering
and for use in a future per-link dynamic powersave, the set_local_ps_mode
function can be called with a delay parameter that sets a per-STA timer
accordingly.

A debug define is added for comfortable debugging output.

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
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: mesh power mode indication in transmitted frames

According to IEEE802.11-2012 a mesh STA shall indicate the current
power mode in transmitted frames. This differs for individually addressed
frames and group addressed frames as well as whether the frames are
addressed to peers or non-peers.
A mesh STA shall indicate its link-specific power mode with the Power
Management field in the Frame Control field and the Mesh Power Save
Level field in the QoS Control field in all individually addressed
Mesh Data frames and QoS Null frames.
The Power Management field set to 1 and the Mesh Power Save Level
subfield set to 0 indicate that the mesh STA is operating in light sleep
mode. The Power Management field set to 0 and the mesh Power Save
Level subfield set to 1 indicate that the mesh STA is operating in
deep sleep mode. The Mesh Power Save Level subfield is reserved, if
the Power Management subfield is set to 0.

A peer-specific mesh power mode transition is indicated by an
individually addressed QoS Null frame to the respective peer.

In frames transmitted to non-peer STA and in management frames the
non-peer mesh power mode is indicated in the Power Management field
in the Frame Control field.
In group addressed Mesh QoS Data frames the Mesh Power Save Level field
in the QoS Control field indicates whether the local STA has any deep
sleep peers.

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
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: mesh non-peer power mode indication in beacons

According to IEEE802.11-2012 a mesh STA shall indicate its
non-peer mesh power mode in the Power Management field of the Frame
Control field of transmitted beacons. It also indicates whether it
has deep sleep peers by setting the Mesh Power Save Level field of
the Mesh Capability field in Beacon and Probe Response frames.

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
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: track neighbor STA power modes

According to IEEE802.11-2012 a mesh peering is always associated between
two mesh STAs. Both mesh STAs have their own mesh power mode for the
mesh peering. This power mode is called the link-specific power mode.
The peer_ps_mode field has been added to the sta_info structure to
represent the peer's link-specific power mode towards the local station.
The nonpeer_ps_mode field has been added to represent the peer's power
mode towards all non-peer stations.

The peer's link-specific power modes are tracked from the Power Management
field in the Frame Control field and the Mesh Power Save Level field
in the QoS Control field. Peer and non-peer modes are tracked independently
from respective frames. This allows fast reconfiguration after a peering
change.

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
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>
{cfg,nl}80211: set local link-specific power mode

The local link-specific power mode defines the mesh power mode in which
the local STA operates towards the peer STA of the corresponding mesh
peering.
This commit adds the possibility of setting the local link-specific
power mode.

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
Signed-off-by: Ivan Bezyazychnyy <ivan.bezyazychnyy@gmail.com>
Signed-off-by: Mike Krinkin <krinkin.m.u@gmail.com>
{cfg,nl}80211: get local and peer mesh power modes

This commit adds the possibility of getting the local link-specific
power mode and the tracked link-specific and non-peer power mode of
the peer.

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
Signed-off-by: Ivan Bezyazychnyy <ivan.bezyazychnyy@gmail.com>
Signed-off-by: Mike Krinkin <krinkin.m.u@gmail.com>
mac80211: add power save support structure to mesh interface

This commit adds the ps_data structure to ieee80211_if_mesh. This structure
contains the TIM map, a counter how of PS neighbors and the actual
group-addressed frame buffer. Functions using this structure are modified
for mesh mode.

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
mac80211: enable frame buffering for PS STA

In case of a neighbor changing its power mode or peering status,
ieee80211_sta_ps_transition is called, which sets or clears the
WLAN_STA_PS flag. This triggers the frame buffering routines for
individually-addressed frames in the tx path used for client mode, which are
re-used here.
Also the num_sta_ps counter is updated, which will trigger the buffering
and release of group-addressed frames after DTIM beacons.

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
{cfg,nl}80211: add awake window to mesh config

This commit adds the dot11MeshAwakeWindowDuration value to the mesh config.
The awake window is a duration in TU describing how long the STA will stay
awake after transmitting its beacon in PS mode.
The value can be changed during mesh operation.

Signed-off-by: Marco Porsch <marco.porsch@s2005.tu-chemnitz.de>
mac80211: add awake window IE to mesh beacons

The awake window value is announced in an IE in beacons if the local STA
is in light or deep sleep mode towards any peer or non-peer.

Signed-off-by: Marco Porsch <marco.porsch@s2005.tu-chemnitz.de>
mac80211: add TIM IE to mesh beacons

Create a TIM IE similarly to AP mode and add it to mesh beacons.
Use the peer's link ID instead of the access point's association ID.

Since the TIM map only supports announcing buffered frames for
IEEE80211_MAX_AID STA, we restrict our mesh LLID/PLID to be <=2007.

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
mac80211: react to awake window and TIM IE

When receiving a neighbor beacon, check if the neighbor indicates
buffered frames in its TIM IE and if it announces an awake window duration.
The routine for frame release towards PS neigbors will then evaluate these
parameters.

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
mac80211: individually-addressed frame release in Peer Service Periods

Peer Service Periods start and end with a PSP trigger frame. The setting of
RSPI and EOSP frame flags determine if a PSP starts or ends and which STA is
the owner of the PSP.
The indication of buffered frames at the peer and the status of the local
buffers determine which type of PSP is started when a beacon from a peer
is received. The buffered frames are transmitted only after the PSP trigger
frame has been acknowledged.
The function ieee80211_sta_ps_deliver_response will automatically try to
set the EOSP for the last flag. In case this is not a QoS data frame, it
will append a QoS Null frame after the last frame.

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
mac80211: configure driver with local mesh PS status

A list of peers in ps mode is created and passed to the driver together
with the configured awake window. Before configuring the driver for PS mode,
check that there are no multiple mesh interfaces, no AP interface and
no active links.
Call driver configuration function in case of configuration change by cfg80211.

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
mac80211: add function for driver to check for ongoing PSP

This patch exports a function, that the driver can call to check if there
are currently Peer Service Periods active. If yes, the radios should stay
in active state.

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