10 #include <linux/kernel.h>
11 #include <linux/random.h>
16 #define PLINK_GET_LLID(p) (p + 2)
17 #define PLINK_GET_PLID(p) (p + 4)
19 #define mod_plink_timer(s, t) (mod_timer(&s->plink_timer, \
20 jiffies + HZ * t / 1000))
22 #define dot11MeshMaxRetries(s) (s->u.mesh.mshcfg.dot11MeshMaxRetries)
23 #define dot11MeshRetryTimeout(s) (s->u.mesh.mshcfg.dot11MeshRetryTimeout)
24 #define dot11MeshConfirmTimeout(s) (s->u.mesh.mshcfg.dot11MeshConfirmTimeout)
25 #define dot11MeshHoldingTimeout(s) (s->u.mesh.mshcfg.dot11MeshHoldingTimeout)
26 #define dot11MeshMaxPeerLinks(s) (s->u.mesh.mshcfg.dot11MeshMaxPeerLinks)
29 #define rssi_threshold_check(sta, sdata) \
30 (sdata->u.mesh.mshcfg.rssi_threshold == 0 ||\
31 (sta && (s8) -ewma_read(&sta->avg_signal) > \
32 sdata->u.mesh.mshcfg.rssi_threshold))
71 static inline void mesh_plink_fsm_restart(
struct sta_info *sta)
74 sta->llid = sta->plid = sta->reason = 0;
75 sta->plink_retries = 0;
118 bool non_ht_sta =
false, ht20_sta =
false;
125 if (sdata != sta->
sdata ||
129 switch (sta->ch_type) {
132 "mesh_plink %pM: nonHT sta (%pM) is present\n",
133 sdata->
vif.addr, sta->
sta.addr);
138 "mesh_plink %pM: HT20 sta (%pM) is present\n",
139 sdata->
vif.addr, sta->
sta.addr);
156 if (sdata->
vif.bss_conf.ht_operation_mode != ht_opmode) {
157 sdata->
vif.bss_conf.ht_operation_mode = ht_opmode;
158 sdata->
u.
mesh.mshcfg.ht_opmode = ht_opmode;
161 "mesh_plink %pM: protection mode changed to %d\n",
162 sdata->
vif.addr, ht_opmode);
178 static u32 __mesh_plink_deactivate(
struct sta_info *sta)
184 changed = mesh_plink_dec_estab_count(sdata);
203 spin_lock_bh(&sta->
lock);
204 changed = __mesh_plink_deactivate(sta);
207 sta->
sta.addr, sta->llid, sta->plid,
209 spin_unlock_bh(&sta->
lock);
221 bool include_plid =
false;
222 u16 peering_proto = 0;
225 sizeof(mgmt->
u.action.u.self_prot);
234 2 + sdata->
u.
mesh.mesh_id_len +
239 sdata->
u.
mesh.ie_len);
242 info = IEEE80211_SKB_CB(skb);
252 mgmt->
u.action.u.self_prot.action_code =
action;
261 memcpy(pos + 2, &plid, 2);
297 if (
WARN_ON(skb_tailroom(skb) < 2 + ie_len))
300 pos =
skb_put(skb, 2 + ie_len);
303 memcpy(pos, &peering_proto, 2);
325 ieee80211_tx_skb(sdata, skb);
348 u32 rates, basic_rates = 0;
352 sband = local->
hw.wiphy->bands[band];
358 if (sdata->
u.
mesh.security & IEEE80211_MESH_SEC_AUTHED) {
366 sta = mesh_plink_alloc(sdata, addr);
372 spin_lock_bh(&sta->
lock);
375 spin_unlock_bh(&sta->
lock);
379 sta->
sta.supp_rates[band] = rates;
391 sta->
sta.ht_cap.cap &=
397 rate_control_rate_init(sta);
398 spin_unlock_bh(&sta->
lock);
413 sta = mesh_peer_init(sdata, hw_addr, elems);
419 sdata->
u.
mesh.accepting_plinks &&
420 sdata->
u.
mesh.mshcfg.auto_open_plinks &&
428 static void mesh_plink_timer(
unsigned long data)
441 if (sta->
sdata->local->quiescing) {
442 sta->plink_timer_was_running =
true;
446 spin_lock_bh(&sta->
lock);
447 if (sta->ignore_plink_timer) {
448 sta->ignore_plink_timer =
false;
449 spin_unlock_bh(&sta->
lock);
453 "Mesh plink timer for %pM fired on state %d\n",
454 sta->
sta.addr, sta->plink_state);
460 switch (sta->plink_state) {
467 "Mesh plink for %pM (retry, timeout): %d %d\n",
468 sta->
sta.addr, sta->plink_retries,
471 sta->plink_timeout = sta->plink_timeout +
472 rand % sta->plink_timeout;
473 ++sta->plink_retries;
475 spin_unlock_bh(&sta->
lock);
477 sta->
sta.addr, llid, 0, 0);
488 spin_unlock_bh(&sta->
lock);
490 sta->
sta.addr, llid, plid, reason);
495 mesh_plink_fsm_restart(sta);
496 spin_unlock_bh(&sta->
lock);
499 spin_unlock_bh(&sta->
lock);
505 void mesh_plink_quiesce(
struct sta_info *sta)
508 sta->plink_timer_was_running =
true;
511 void mesh_plink_restart(
struct sta_info *sta)
513 if (sta->plink_timer_was_running) {
515 sta->plink_timer_was_running =
false;
520 static inline void mesh_plink_timer_set(
struct sta_info *sta,
int timeout)
522 sta->plink_timer.expires =
jiffies + (
HZ * timeout / 1000);
523 sta->plink_timer.data = (
unsigned long) sta;
524 sta->plink_timer.function = mesh_plink_timer;
525 sta->plink_timeout = timeout;
537 spin_lock_bh(&sta->
lock);
542 spin_unlock_bh(&sta->
lock);
547 spin_unlock_bh(&sta->
lock);
549 "Mesh plink: starting establishment with %pM\n",
553 sta->
sta.addr, llid, 0, 0);
561 spin_lock_bh(&sta->
lock);
562 changed = __mesh_plink_deactivate(sta);
564 spin_unlock_bh(&sta->
lock);
578 bool matches_local =
true;
583 static const char *mplstates[] = {
597 if (is_multicast_ether_addr(mgmt->
da)) {
599 "Mesh plink: ignore frame from multicast address\n");
603 baseaddr = mgmt->
u.action.u.self_prot.variable;
604 baselen = (
u8 *) mgmt->
u.action.u.self_prot.variable - (
u8 *)
mgmt;
605 if (mgmt->
u.action.u.self_prot.action_code ==
613 "Mesh plink: missing necessary peer link ie\n");
617 sdata->
u.
mesh.security == IEEE80211_MESH_SEC_NONE) {
619 "Mesh plink: can't establish link with secure peer\n");
623 ftype = mgmt->
u.action.u.self_prot.action_code;
630 "Mesh plink: incorrect plink ie length %d %d\n",
637 mpl_dbg(sdata,
"Mesh plink: missing necessary ie\n");
652 mpl_dbg(sdata,
"Mesh plink: cls or cnf from unknown peer\n");
659 mpl_dbg(sdata,
"Mesh plink: %pM does not meet rssi threshold\n",
666 mpl_dbg(sdata,
"Mesh plink: Action frame from non-authed peer\n");
680 matches_local =
false;
693 if (!sta && !matches_local) {
698 mgmt->
sa, llid, plid, reason);
702 if (!mesh_plink_free_count(sdata)) {
703 mpl_dbg(sdata,
"Mesh plink error: no more free plinks\n");
708 }
else if (matches_local) {
711 if (!mesh_plink_free_count(sdata) ||
712 (sta->plid && sta->plid != plid))
718 if (!mesh_plink_free_count(sdata) ||
719 (sta->llid != llid || sta->plid != plid))
736 else if (sta->plid != plid)
738 else if (ie_len == 7 && sta->llid != llid)
744 mpl_dbg(sdata,
"Mesh plink: unknown frame subtype\n");
752 sta = mesh_peer_init(sdata, mgmt->
sa, &elems);
754 mpl_dbg(sdata,
"Mesh plink: failed to init peer!\n");
761 "Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
762 mgmt->
sa, mplstates[sta->plink_state],
766 spin_lock_bh(&sta->
lock);
767 switch (sta->plink_state) {
772 mesh_plink_fsm_restart(sta);
773 spin_unlock_bh(&sta->
lock);
781 spin_unlock_bh(&sta->
lock);
782 mesh_plink_frame_tx(sdata,
784 sta->
sta.addr, llid, 0, 0);
785 mesh_plink_frame_tx(sdata,
787 sta->
sta.addr, llid, plid, 0);
790 spin_unlock_bh(&sta->
lock);
807 sta->ignore_plink_timer =
true;
810 spin_unlock_bh(&sta->
lock);
811 mesh_plink_frame_tx(sdata,
813 sta->
sta.addr, llid, plid, reason);
820 spin_unlock_bh(&sta->
lock);
821 mesh_plink_frame_tx(sdata,
823 sta->
sta.addr, llid, plid, 0);
829 sta->ignore_plink_timer =
true;
831 spin_unlock_bh(&sta->
lock);
834 spin_unlock_bh(&sta->
lock);
851 sta->ignore_plink_timer =
true;
854 spin_unlock_bh(&sta->
lock);
856 sta->
sta.addr, llid, plid, reason);
860 spin_unlock_bh(&sta->
lock);
861 mesh_plink_frame_tx(sdata,
863 sta->
sta.addr, llid, plid, 0);
868 spin_unlock_bh(&sta->
lock);
869 changed |= mesh_plink_inc_estab_count(sdata);
870 changed |= mesh_set_ht_prot_mode(sdata);
871 mpl_dbg(sdata,
"Mesh plink with %pM ESTABLISHED\n",
875 spin_unlock_bh(&sta->
lock);
892 sta->ignore_plink_timer =
true;
895 spin_unlock_bh(&sta->
lock);
896 mesh_plink_frame_tx(sdata,
898 sta->
sta.addr, llid, plid, reason);
903 spin_unlock_bh(&sta->
lock);
904 changed |= mesh_plink_inc_estab_count(sdata);
905 changed |= mesh_set_ht_prot_mode(sdata);
906 mpl_dbg(sdata,
"Mesh plink with %pM ESTABLISHED\n",
908 mesh_plink_frame_tx(sdata,
910 sta->
sta.addr, llid, plid, 0);
913 spin_unlock_bh(&sta->
lock);
923 changed |= __mesh_plink_deactivate(sta);
927 spin_unlock_bh(&sta->
lock);
928 changed |= mesh_set_ht_prot_mode(sdata);
930 sta->
sta.addr, llid, plid, reason);
934 spin_unlock_bh(&sta->
lock);
935 mesh_plink_frame_tx(sdata,
937 sta->
sta.addr, llid, plid, 0);
940 spin_unlock_bh(&sta->
lock);
948 sta->ignore_plink_timer = 1;
949 mesh_plink_fsm_restart(sta);
950 spin_unlock_bh(&sta->
lock);
957 reason = sta->reason;
958 spin_unlock_bh(&sta->
lock);
960 sta->
sta.addr, llid, plid, reason);
963 spin_unlock_bh(&sta->
lock);
970 spin_unlock_bh(&sta->
lock);