mac80211: mesh: factor out common plink close code

Reject and accepted close events always put the host in the
holding state and compute a reason code based only on the
current state.  Put this in a function to save some duplicated
code.

Signed-off-by: Bob Copeland <me@bobcopeland.com>
mac80211: mesh: cleanup plink open when !matches_local

Drop the else from "if (x) { return; } else ... " and
remove the unnecessary llid assignment.

Signed-off-by: Bob Copeland <me@bobcopeland.com>
mac80211: mesh_plink: group basic fitness checks

The initial frame checks differ depending on whether this is
a new peer or not, but they were all intermixed with sta checks
as necessary.  Group them together so the two cases are clearer.

Signed-off-by: Bob Copeland <me@bobcopeland.com>
mac80211: mesh: rewrite rssi_threshold_check in C

Use C instead of cpp for type checking.  Also swap the arguments
into the usual sdata -> sta order.

Signed-off-by: Bob Copeland <me@bobcopeland.com>
mac80211: mesh_plink: collapse the two switch statements together

The matches_local check can just be done when looking at the
individual action types.

Signed-off-by: Bob Copeland <me@bobcopeland.com>
mac80211: mesh_plink: don't ignore holding timer

The ignore_plink_timer flag is set when doing mod_timer() if
the timer was not previously active.  This is to avoid executing
the timeout if del_timer() was subsequently called.  However,
del_timer() only happens if we are moving to ESTAB state or
get a close frame while in HOLDING.

We cannot leave HOLDING and re-enter ESTAB unless we receive a
close frame (in which case ignore_plink_timer is already set) or
if the timeout expires, so there actually isn't a case where
this is needed on mod_timer().
mac80211: return -ENOMEM in mesh_plink_frame_tx

All other paths return an error code, do the same here.

Signed-off-by: Bob Copeland <me@bobcopeland.com>
mac80211: extract mesh estab code into a function

Removes some code duplication.

Signed-off-by: Bob Copeland <me@bobcopeland.com>
mac80211: hold sta->lock across plink fsm switch()

Rather than unlock at the end of each case, do it once after
all is said and done.

Signed-off-by: Bob Copeland <me@bobcopeland.com>
mac80211: remove unused mesh_mgmt_ies_add() prototype

Said function was removed some time ago.

Signed-off-by: Bob Copeland <me@bobcopeland.com>
mac80211: factor peering frame processing into own function

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>
mac80211: remove mysterious peering ie_len check

According to IEEE802.11-2012 (8.4.2.104), no peering
management element exists with length 7. This code seems
to have been part of the original implementation, but it's
purpose is now unknown, so remove it.

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>
mac80211: factor out plink event gathering

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>
mac80211: consolidate rcu unlocks in plink frame rx

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>
mac80211: assign sta plid early

If we store the peer link ID right after initializing a
new neighbor, there is no need to do it later in the
peering FSM.

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>
mac80211: initialize llid

If the peer doesn't have an llid for us, the event
gathering function won't use it anyway (based on
frametype), but initialize it so gcc and coverity don't
complain.

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>
mac80211: factor out peering FSM

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>
mac80211: consolidate calls to plink_frame_tx

sta->reason is always accurate, since it is really only
the close reason. Once the holding timer expires this
resets to 0.

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>
mac80211: peering fsm formatting

Clean up whitespace.

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>