{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: Ivan Bezyazychnyy <ivan.bezyazychnyy@gmail.com>
Signed-off-by: Mike Krinkin <krinkin.m.u@gmail.com>
Signed-off-by: Marco Porsch <marco.porsch@s2005.tu-chemnitz.de>
{cfg,nl}80211: setting and getting default mesh power mode

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

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

According to the 80211s standard 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 the IEEE80211s standard 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.

A debug define is added for comfortable debugging output.

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

According to the IEEE80211s standard 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: Ivan Bezyazychnyy <ivan.bezyazychnyy@gmail.com>
Signed-off-by: Mike Krinkin <krinkin.m.u@gmail.com>
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
Signed-off-by: Marco Porsch <marco.porsch@s2005.tu-chemnitz.de>
mac80211: mesh non-peer power mode indication in beacons

According to the IEEE80211s standard 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: Ivan Bezyazychnyy <ivan.bezyazychnyy@gmail.com>
Signed-off-by: Mike Krinkin <krinkin.m.u@gmail.com>
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
Signed-off-by: Marco Porsch <marco.porsch@s2005.tu-chemnitz.de>
mac80211: tracking of neighbor STA power modes

According to the IEEE80211s standard 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: Ivan Bezyazychnyy <ivan.bezyazychnyy@gmail.com>
Signed-off-by: Mike Krinkin <krinkin.m.u@gmail.com>
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
Signed-off-by: Marco Porsch <marco.porsch@s2005.tu-chemnitz.de>
{cfg,nl}80211: setting 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: Ivan Bezyazychnyy <ivan.bezyazychnyy@gmail.com>
Signed-off-by: Mike Krinkin <krinkin.m.u@gmail.com>
Signed-off-by: Marco Porsch <marco.porsch@s2005.tu-chemnitz.de>
{cfg,nl}80211: getting 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: Ivan Bezyazychnyy <ivan.bezyazychnyy@gmail.com>
Signed-off-by: Mike Krinkin <krinkin.m.u@gmail.com>
Signed-off-by: Marco Porsch <marco.porsch@s2005.tu-chemnitz.de>
mac80211: individually addressed frame PS buffering

ieee80211_sta_ps_transition sets the WLAN_STA_PS flag. This triggers
the PS buffering routines in the tx path used for client mode, which
are re-used here.

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
mac80211: mesh group addressed frame PS buffering and release

The mac80211 group addressed frame buffering and release code is written
focused on managed mode. Instead of re-writing everything, we reuse
the existing ieee80211_if_ap structure, and access it with the sdata->bss
pointer. The struct is allocated on interface open and freed on interface
stop. The managed mode buffer and release functions are modified to accept
our ieee80211_if_ap.

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

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

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.

There is a bug in ieee80211_beacon_add_tim that currently causes
mischief when a PLID/AID >255 is used. As a workaround we restrict
our LLID/PLID to be <=255.

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

When receiving an awake window IE, check if the neighbor indicates
buffered frames in its TIM IE and if frames are buffered for that peer
in the local STA's PS buffer. If both are true, start a bidirectional PSP.
If only the peer has frames buffered for the local STA, start a PSP in
which the peer is the owner (similar to polling).

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

To start or end a PSP, send a PSP trigger frame with RSPI and/or EOSP flag
set in the frame's QoS control field.
Workarounds are added to bypass HWMP, to preserve the RSPI flag and to avoid
getting a mesh control header flag (Nulls don't have a mesh header which is
part of the frame body).

A PSP starts when a trigger frame is received or a sent trigger frame is
acknowledged. In this case the STA checks for buffered frames. In case none
are found the STA sends a QoS Null to end the PSP.

PSPs are of variable length according to the (re-)fill rate of the buffer. After
the last packet of the current buffer content has been sent and acknowleded, the
buffer is checked again if new packets have been queued in the meantime.
Therefore the last buffered frame of a PSP iteration is marked with
IEEE80211_TX_STATUS_EOSP. ieee80211_mesh_ps_deliver_psp will be called again
after this frame has been acknowledged. Then the PS buffer will be checked
once again, if new frames have been buffered. If yes, the PSP will continue.
If not, send a QoS Null with EOSP field set to end the local part of the PSP.
Do recalc_tim after the PSP has ended.
A new frame release reason is added to control frame releases during a PSP.

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
mac80211: pass mesh ps information to driver

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: callback for driver to check for ongoing PSP

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
ath9k: initial mesh beacon config

We need to set an initial sleepduration to wake up again for the first time
after enabling powersave.

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
ath9k: take powersave parametes from mac80211

Take a list of wakeup events to regularly wake up for.
In the local ath9k_wakeup_event structure a peer MAC address is assigned to an ath9k_beacon_state.
In case of deep sleep neighbors, wake up only for their DTIM beacons.

Also locally store awake window duration.

Signed-off-by: Marco Porsch <marco.porsch@etit.tu-chemnitz.de>
ath9k: maintain wakeup event list

If a wakeup list is stored, receive beacons of listed STA and evaluate the timing information to predict the next beacon.
If one entry has not been updated recently, assume the beacon has been missed and keep awake to eventually catch a beacon.
If the STA is completely dead or out of range, a consequent peer update from mac80211 will remove this entry from the wakeup list.

Extract beacon interval, DTIM period and TBTT_adjusting flag from received beacon's TIM IE.
In case of indicated TBTT adjustment of peeer, we should wake up 0.04% of peers beacon interval earlier. Use simpel approximation here.

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