Skip to content

Commit b8456a1

Browse files
chunyeowjmberg-intel
authored andcommitted
{nl,cfg,mac}80211: implement mesh channel switch userspace API
Implement the required procedures for mesh channel switching as defined in the IEEE Std 802.11-2012 section 10.9.8.4.3 and also handle the CSA and MCSP elements as followed: * Add the function for updating the beacon and probe response frames with CSA and MCSP elements during the period of switching to the new channel. Both CSA and MCSP elements must be included in beacon and probe response frames until the intended channel switch time. * The ifmsh->csa_settings is set to NULL and the CSA and MCSP elements will then be removed from the beacon or probe response frames once the new channel is switched to. Signed-off-by: Chun-Yeow Yeoh <yeohchunyeow@cozybit.com> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent c6da674 commit b8456a1

6 files changed

Lines changed: 139 additions & 3 deletions

File tree

‎net/mac80211/cfg.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2994,6 +2994,13 @@ void ieee80211_csa_finalize_work(struct work_struct *work)
29942994
case NL80211_IFTYPE_ADHOC:
29952995
ieee80211_ibss_finish_csa(sdata);
29962996
break;
2997+
#ifdef CONFIG_MAC80211_MESH
2998+
case NL80211_IFTYPE_MESH_POINT:
2999+
err = ieee80211_mesh_finish_csa(sdata);
3000+
if (err < 0)
3001+
return;
3002+
break;
3003+
#endif
29973004
default:
29983005
WARN_ON(1);
29993006
return;
@@ -3113,7 +3120,7 @@ static int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
31133120
params->chandef.chan->band)
31143121
return -EINVAL;
31153122

3116-
err = ieee80211_send_action_csa(sdata, params);
3123+
err = ieee80211_mesh_csa_beacon(sdata, params, true);
31173124
if (err < 0)
31183125
return err;
31193126
break;

‎net/mac80211/ieee80211_i.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,11 @@ struct ieee80211_mesh_sync_ops {
543543
/* add other framework functions here */
544544
};
545545

546+
struct mesh_csa_settings {
547+
struct rcu_head rcu_head;
548+
struct cfg80211_csa_settings settings;
549+
};
550+
546551
struct ieee80211_if_mesh {
547552
struct timer_list housekeeping_timer;
548553
struct timer_list mesh_path_timer;
@@ -604,7 +609,9 @@ struct ieee80211_if_mesh {
604609
int ps_peers_deep_sleep;
605610
struct ps_data ps;
606611
/* Channel Switching Support */
612+
struct mesh_csa_settings __rcu *csa;
607613
bool chsw_init;
614+
u8 chsw_ttl;
608615
u16 pre_value;
609616
};
610617

@@ -1356,6 +1363,10 @@ void ieee80211_ibss_stop(struct ieee80211_sub_if_data *sdata);
13561363
void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata);
13571364
void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
13581365
struct sk_buff *skb);
1366+
int ieee80211_mesh_csa_beacon(struct ieee80211_sub_if_data *sdata,
1367+
struct cfg80211_csa_settings *csa_settings,
1368+
bool csa_action);
1369+
int ieee80211_mesh_finish_csa(struct ieee80211_sub_if_data *sdata);
13591370

13601371
/* scan/BSS handling */
13611372
void ieee80211_scan_work(struct work_struct *work);

‎net/mac80211/mesh.c‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <asm/unaligned.h>
1313
#include "ieee80211_i.h"
1414
#include "mesh.h"
15+
#include "driver-ops.h"
1516

1617
static int mesh_allocated;
1718
static struct kmem_cache *rm_cache;
@@ -610,6 +611,7 @@ ieee80211_mesh_build_beacon(struct ieee80211_if_mesh *ifmsh)
610611
struct sk_buff *skb;
611612
struct ieee80211_mgmt *mgmt;
612613
struct ieee80211_chanctx_conf *chanctx_conf;
614+
struct mesh_csa_settings *csa;
613615
enum ieee80211_band band;
614616
u8 *pos;
615617
struct ieee80211_sub_if_data *sdata;
@@ -624,6 +626,10 @@ ieee80211_mesh_build_beacon(struct ieee80211_if_mesh *ifmsh)
624626

625627
head_len = hdr_len +
626628
2 + /* NULL SSID */
629+
/* Channel Switch Announcement */
630+
2 + sizeof(struct ieee80211_channel_sw_ie) +
631+
/* Mesh Channel Swith Parameters */
632+
2 + sizeof(struct ieee80211_mesh_chansw_params_ie) +
627633
2 + 8 + /* supported rates */
628634
2 + 3; /* DS params */
629635
tail_len = 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
@@ -665,6 +671,38 @@ ieee80211_mesh_build_beacon(struct ieee80211_if_mesh *ifmsh)
665671
*pos++ = WLAN_EID_SSID;
666672
*pos++ = 0x0;
667673

674+
rcu_read_lock();
675+
csa = rcu_dereference(ifmsh->csa);
676+
if (csa) {
677+
__le16 pre_value;
678+
679+
pos = skb_put(skb, 13);
680+
memset(pos, 0, 13);
681+
*pos++ = WLAN_EID_CHANNEL_SWITCH;
682+
*pos++ = 3;
683+
*pos++ = 0x0;
684+
*pos++ = ieee80211_frequency_to_channel(
685+
csa->settings.chandef.chan->center_freq);
686+
sdata->csa_counter_offset_beacon = hdr_len + 6;
687+
*pos++ = csa->settings.count;
688+
*pos++ = WLAN_EID_CHAN_SWITCH_PARAM;
689+
*pos++ = 6;
690+
if (ifmsh->chsw_init) {
691+
*pos++ = ifmsh->mshcfg.dot11MeshTTL;
692+
*pos |= WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR;
693+
} else {
694+
*pos++ = ifmsh->chsw_ttl;
695+
}
696+
*pos++ |= csa->settings.block_tx ?
697+
WLAN_EID_CHAN_SWITCH_PARAM_TX_RESTRICT : 0x00;
698+
put_unaligned_le16(WLAN_REASON_MESH_CHAN, pos);
699+
pos += 2;
700+
pre_value = cpu_to_le16(ifmsh->pre_value);
701+
memcpy(pos, &pre_value, 2);
702+
pos += 2;
703+
}
704+
rcu_read_unlock();
705+
668706
if (ieee80211_add_srates_ie(sdata, skb, true, band) ||
669707
mesh_add_ds_params_ie(sdata, skb))
670708
goto out_free;
@@ -920,6 +958,65 @@ static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
920958
stype, mgmt, &elems, rx_status);
921959
}
922960

961+
int ieee80211_mesh_finish_csa(struct ieee80211_sub_if_data *sdata)
962+
{
963+
struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
964+
struct mesh_csa_settings *tmp_csa_settings;
965+
int ret = 0;
966+
967+
/* Reset the TTL value and Initiator flag */
968+
ifmsh->chsw_init = false;
969+
ifmsh->chsw_ttl = 0;
970+
971+
/* Remove the CSA and MCSP elements from the beacon */
972+
tmp_csa_settings = rcu_dereference(ifmsh->csa);
973+
rcu_assign_pointer(ifmsh->csa, NULL);
974+
kfree_rcu(tmp_csa_settings, rcu_head);
975+
ret = ieee80211_mesh_rebuild_beacon(sdata);
976+
if (ret)
977+
return -EINVAL;
978+
979+
ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
980+
981+
mcsa_dbg(sdata, "complete switching to center freq %d MHz",
982+
sdata->vif.bss_conf.chandef.chan->center_freq);
983+
return 0;
984+
}
985+
986+
int ieee80211_mesh_csa_beacon(struct ieee80211_sub_if_data *sdata,
987+
struct cfg80211_csa_settings *csa_settings,
988+
bool csa_action)
989+
{
990+
struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
991+
struct mesh_csa_settings *tmp_csa_settings;
992+
int ret = 0;
993+
994+
tmp_csa_settings = kmalloc(sizeof(*tmp_csa_settings),
995+
GFP_ATOMIC);
996+
if (!tmp_csa_settings)
997+
return -ENOMEM;
998+
999+
memcpy(&tmp_csa_settings->settings, csa_settings,
1000+
sizeof(struct cfg80211_csa_settings));
1001+
1002+
rcu_assign_pointer(ifmsh->csa, tmp_csa_settings);
1003+
1004+
ret = ieee80211_mesh_rebuild_beacon(sdata);
1005+
if (ret) {
1006+
tmp_csa_settings = rcu_dereference(ifmsh->csa);
1007+
rcu_assign_pointer(ifmsh->csa, NULL);
1008+
kfree_rcu(tmp_csa_settings, rcu_head);
1009+
return ret;
1010+
}
1011+
1012+
ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
1013+
1014+
if (csa_action)
1015+
ieee80211_send_action_csa(sdata, csa_settings);
1016+
1017+
return 0;
1018+
}
1019+
9231020
static int mesh_fwd_csa_frame(struct ieee80211_sub_if_data *sdata,
9241021
struct ieee80211_mgmt *mgmt, size_t len)
9251022
{
@@ -942,6 +1039,7 @@ static int mesh_fwd_csa_frame(struct ieee80211_sub_if_data *sdata,
9421039
offset_ttl = (len < 42) ? 7 : 10;
9431040
*(pos + offset_ttl) -= 1;
9441041
*(pos + offset_ttl + 1) &= ~WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR;
1042+
sdata->u.mesh.chsw_ttl = *(pos + offset_ttl);
9451043

9461044
memcpy(mgmt_fwd, mgmt, len);
9471045
eth_broadcast_addr(mgmt_fwd->da);

‎net/mac80211/rx.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2593,13 +2593,16 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
25932593
break;
25942594

25952595
if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2596-
sdata->vif.type != NL80211_IFTYPE_ADHOC)
2596+
sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2597+
sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
25972598
break;
25982599

25992600
if (sdata->vif.type == NL80211_IFTYPE_STATION)
26002601
bssid = sdata->u.mgd.bssid;
26012602
else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
26022603
bssid = sdata->u.ibss.bssid;
2604+
else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
2605+
bssid = mgmt->sa;
26032606
else
26042607
break;
26052608

‎net/mac80211/tx.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,6 +2398,10 @@ static void ieee80211_update_csa(struct ieee80211_sub_if_data *sdata,
23982398
beacon_data = beacon->head;
23992399
beacon_data_len = beacon->head_len;
24002400
break;
2401+
case NL80211_IFTYPE_MESH_POINT:
2402+
beacon_data = beacon->head;
2403+
beacon_data_len = beacon->head_len;
2404+
break;
24012405
default:
24022406
return;
24032407
}
@@ -2452,6 +2456,15 @@ bool ieee80211_csa_is_complete(struct ieee80211_vif *vif)
24522456
if (!beacon)
24532457
goto out;
24542458

2459+
beacon_data = beacon->head;
2460+
beacon_data_len = beacon->head_len;
2461+
} else if (vif->type == NL80211_IFTYPE_MESH_POINT) {
2462+
struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2463+
2464+
beacon = rcu_dereference(ifmsh->beacon);
2465+
if (!beacon)
2466+
goto out;
2467+
24552468
beacon_data = beacon->head;
24562469
beacon_data_len = beacon->head_len;
24572470
} else {
@@ -2559,6 +2572,9 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
25592572
if (!bcn)
25602573
goto out;
25612574

2575+
if (sdata->vif.csa_active)
2576+
ieee80211_update_csa(sdata, bcn);
2577+
25622578
if (ifmsh->sync_ops)
25632579
ifmsh->sync_ops->adjust_tbtt(
25642580
sdata);

‎net/wireless/nl80211.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10813,7 +10813,8 @@ void cfg80211_ch_switch_notify(struct net_device *dev,
1081310813

1081410814
if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
1081510815
wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10816-
wdev->iftype != NL80211_IFTYPE_ADHOC))
10816+
wdev->iftype != NL80211_IFTYPE_ADHOC &&
10817+
wdev->iftype != NL80211_IFTYPE_MESH_POINT))
1081710818
goto out;
1081810819

1081910820
wdev->channel = chandef->chan;

0 commit comments

Comments
 (0)