Skip to content

Commit 16ef1fe

Browse files
Simon Wunderlichjmberg-intel
authored andcommitted
nl80211/cfg80211: add channel switch command
To allow channel switch announcements within beacons, add the channel switch command to nl80211/cfg80211. This is implementation is intended for AP and (later) IBSS mode. Signed-off-by: Simon Wunderlich <[email protected]> Signed-off-by: Mathias Kretschmer <[email protected]> Signed-off-by: Johannes Berg <[email protected]>
1 parent 7cf1f14 commit 16ef1fe

File tree

5 files changed

+229
-1
lines changed

5 files changed

+229
-1
lines changed

include/net/cfg80211.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,30 @@ struct cfg80211_ap_settings {
665665
bool radar_required;
666666
};
667667

668+
/**
669+
* struct cfg80211_csa_settings - channel switch settings
670+
*
671+
* Used for channel switch
672+
*
673+
* @chandef: defines the channel to use after the switch
674+
* @beacon_csa: beacon data while performing the switch
675+
* @counter_offset_beacon: offset for the counter within the beacon (tail)
676+
* @counter_offset_presp: offset for the counter within the probe response
677+
* @beacon_after: beacon data to be used on the new channel
678+
* @radar_required: whether radar detection is required on the new channel
679+
* @block_tx: whether transmissions should be blocked while changing
680+
* @count: number of beacons until switch
681+
*/
682+
struct cfg80211_csa_settings {
683+
struct cfg80211_chan_def chandef;
684+
struct cfg80211_beacon_data beacon_csa;
685+
u16 counter_offset_beacon, counter_offset_presp;
686+
struct cfg80211_beacon_data beacon_after;
687+
bool radar_required;
688+
bool block_tx;
689+
u8 count;
690+
};
691+
668692
/**
669693
* enum station_parameters_apply_mask - station parameter values to apply
670694
* @STATION_PARAM_APPLY_UAPSD: apply new uAPSD parameters (uapsd_queues, max_sp)
@@ -2139,6 +2163,8 @@ struct cfg80211_update_ft_ies_params {
21392163
* @crit_proto_stop: Indicates critical protocol no longer needs increased link
21402164
* reliability. This operation can not fail.
21412165
* @set_coalesce: Set coalesce parameters.
2166+
*
2167+
* @channel_switch: initiate channel-switch procedure (with CSA)
21422168
*/
21432169
struct cfg80211_ops {
21442170
int (*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow);
@@ -2376,6 +2402,10 @@ struct cfg80211_ops {
23762402
struct wireless_dev *wdev);
23772403
int (*set_coalesce)(struct wiphy *wiphy,
23782404
struct cfg80211_coalesce *coalesce);
2405+
2406+
int (*channel_switch)(struct wiphy *wiphy,
2407+
struct net_device *dev,
2408+
struct cfg80211_csa_settings *params);
23792409
};
23802410

23812411
/*
@@ -2441,6 +2471,8 @@ struct cfg80211_ops {
24412471
* @WIPHY_FLAG_OFFCHAN_TX: Device supports direct off-channel TX.
24422472
* @WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL: Device supports remain-on-channel call.
24432473
* @WIPHY_FLAG_SUPPORTS_5_10_MHZ: Device supports 5 MHz and 10 MHz channels.
2474+
* @WIPHY_FLAG_HAS_CHANNEL_SWITCH: Device supports channel switch in
2475+
* beaconing mode (AP, IBSS, Mesh, ...).
24442476
*/
24452477
enum wiphy_flags {
24462478
WIPHY_FLAG_CUSTOM_REGULATORY = BIT(0),
@@ -2465,6 +2497,7 @@ enum wiphy_flags {
24652497
WIPHY_FLAG_OFFCHAN_TX = BIT(20),
24662498
WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL = BIT(21),
24672499
WIPHY_FLAG_SUPPORTS_5_10_MHZ = BIT(22),
2500+
WIPHY_FLAG_HAS_CHANNEL_SWITCH = BIT(23),
24682501
};
24692502

24702503
/**

include/uapi/linux/nl80211.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,16 @@
676676
* @NL80211_CMD_GET_COALESCE: Get currently supported coalesce rules.
677677
* @NL80211_CMD_SET_COALESCE: Configure coalesce rules or clear existing rules.
678678
*
679+
* @NL80211_CMD_CHANNEL_SWITCH: Perform a channel switch by announcing the
680+
* the new channel information (Channel Switch Announcement - CSA)
681+
* in the beacon for some time (as defined in the
682+
* %NL80211_ATTR_CH_SWITCH_COUNT parameter) and then change to the
683+
* new channel. Userspace provides the new channel information (using
684+
* %NL80211_ATTR_WIPHY_FREQ and the attributes determining channel
685+
* width). %NL80211_ATTR_CH_SWITCH_BLOCK_TX may be supplied to inform
686+
* other station that transmission must be blocked until the channel
687+
* switch is complete.
688+
*
679689
* @NL80211_CMD_MAX: highest used command number
680690
* @__NL80211_CMD_AFTER_LAST: internal use
681691
*/
@@ -841,6 +851,8 @@ enum nl80211_commands {
841851
NL80211_CMD_GET_COALESCE,
842852
NL80211_CMD_SET_COALESCE,
843853

854+
NL80211_CMD_CHANNEL_SWITCH,
855+
844856
/* add new commands above here */
845857

846858
/* used to define NL80211_CMD_MAX below */
@@ -1469,6 +1481,18 @@ enum nl80211_commands {
14691481
*
14701482
* @NL80211_ATTR_COALESCE_RULE: Coalesce rule information.
14711483
*
1484+
* @NL80211_ATTR_CH_SWITCH_COUNT: u32 attribute specifying the number of TBTT's
1485+
* until the channel switch event.
1486+
* @NL80211_ATTR_CH_SWITCH_BLOCK_TX: flag attribute specifying that transmission
1487+
* must be blocked on the current channel (before the channel switch
1488+
* operation).
1489+
* @NL80211_ATTR_CSA_IES: Nested set of attributes containing the IE information
1490+
* for the time while performing a channel switch.
1491+
* @NL80211_ATTR_CSA_C_OFF_BEACON: Offset of the channel switch counter
1492+
* field in the beacons tail (%NL80211_ATTR_BEACON_TAIL).
1493+
* @NL80211_ATTR_CSA_C_OFF_PRESP: Offset of the channel switch counter
1494+
* field in the probe response (%NL80211_ATTR_PROBE_RESP).
1495+
*
14721496
* @NL80211_ATTR_MAX: highest attribute number currently defined
14731497
* @__NL80211_ATTR_AFTER_LAST: internal use
14741498
*/
@@ -1771,6 +1795,12 @@ enum nl80211_attrs {
17711795

17721796
NL80211_ATTR_COALESCE_RULE,
17731797

1798+
NL80211_ATTR_CH_SWITCH_COUNT,
1799+
NL80211_ATTR_CH_SWITCH_BLOCK_TX,
1800+
NL80211_ATTR_CSA_IES,
1801+
NL80211_ATTR_CSA_C_OFF_BEACON,
1802+
NL80211_ATTR_CSA_C_OFF_PRESP,
1803+
17741804
/* add attributes here, update the policy in nl80211.c */
17751805

17761806
__NL80211_ATTR_AFTER_LAST,

net/wireless/nl80211.c

Lines changed: 121 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,11 @@ static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
349349
[NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
350350
.len = IEEE80211_MAX_DATA_LEN },
351351
[NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
352+
[NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
353+
[NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
354+
[NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
355+
[NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 },
356+
[NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 },
352357
};
353358

354359
/* policy for the key attributes */
@@ -1422,6 +1427,8 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
14221427
if (state->split) {
14231428
CMD(crit_proto_start, CRIT_PROTOCOL_START);
14241429
CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
1430+
if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
1431+
CMD(channel_switch, CHANNEL_SWITCH);
14251432
}
14261433

14271434
#ifdef CONFIG_NL80211_TESTMODE
@@ -5613,6 +5620,111 @@ static int nl80211_start_radar_detection(struct sk_buff *skb,
56135620
return err;
56145621
}
56155622

5623+
static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5624+
{
5625+
struct cfg80211_registered_device *rdev = info->user_ptr[0];
5626+
struct net_device *dev = info->user_ptr[1];
5627+
struct wireless_dev *wdev = dev->ieee80211_ptr;
5628+
struct cfg80211_csa_settings params;
5629+
/* csa_attrs is defined static to avoid waste of stack size - this
5630+
* function is called under RTNL lock, so this should not be a problem.
5631+
*/
5632+
static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5633+
u8 radar_detect_width = 0;
5634+
int err;
5635+
5636+
if (!rdev->ops->channel_switch ||
5637+
!(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5638+
return -EOPNOTSUPP;
5639+
5640+
/* may add IBSS support later */
5641+
if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5642+
dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5643+
return -EOPNOTSUPP;
5644+
5645+
memset(&params, 0, sizeof(params));
5646+
5647+
if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5648+
!info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5649+
return -EINVAL;
5650+
5651+
/* only important for AP, IBSS and mesh create IEs internally */
5652+
if (!info->attrs[NL80211_ATTR_CSA_IES])
5653+
return -EINVAL;
5654+
5655+
/* useless if AP is not running */
5656+
if (!wdev->beacon_interval)
5657+
return -EINVAL;
5658+
5659+
params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5660+
5661+
err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5662+
if (err)
5663+
return err;
5664+
5665+
err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5666+
info->attrs[NL80211_ATTR_CSA_IES],
5667+
nl80211_policy);
5668+
if (err)
5669+
return err;
5670+
5671+
err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5672+
if (err)
5673+
return err;
5674+
5675+
if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5676+
return -EINVAL;
5677+
5678+
params.counter_offset_beacon =
5679+
nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5680+
if (params.counter_offset_beacon >= params.beacon_csa.tail_len)
5681+
return -EINVAL;
5682+
5683+
/* sanity check - counters should be the same */
5684+
if (params.beacon_csa.tail[params.counter_offset_beacon] !=
5685+
params.count)
5686+
return -EINVAL;
5687+
5688+
if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
5689+
params.counter_offset_presp =
5690+
nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5691+
if (params.counter_offset_presp >=
5692+
params.beacon_csa.probe_resp_len)
5693+
return -EINVAL;
5694+
5695+
if (params.beacon_csa.probe_resp[params.counter_offset_presp] !=
5696+
params.count)
5697+
return -EINVAL;
5698+
}
5699+
5700+
err = nl80211_parse_chandef(rdev, info, &params.chandef);
5701+
if (err)
5702+
return err;
5703+
5704+
if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
5705+
return -EINVAL;
5706+
5707+
err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
5708+
if (err < 0) {
5709+
return err;
5710+
} else if (err) {
5711+
radar_detect_width = BIT(params.chandef.width);
5712+
params.radar_required = true;
5713+
}
5714+
5715+
err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5716+
params.chandef.chan,
5717+
CHAN_MODE_SHARED,
5718+
radar_detect_width);
5719+
if (err)
5720+
return err;
5721+
5722+
if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
5723+
params.block_tx = true;
5724+
5725+
return rdev_channel_switch(rdev, dev, &params);
5726+
}
5727+
56165728
static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
56175729
u32 seq, int flags,
56185730
struct cfg80211_registered_device *rdev,
@@ -9361,7 +9473,15 @@ static struct genl_ops nl80211_ops[] = {
93619473
.flags = GENL_ADMIN_PERM,
93629474
.internal_flags = NL80211_FLAG_NEED_WIPHY |
93639475
NL80211_FLAG_NEED_RTNL,
9364-
}
9476+
},
9477+
{
9478+
.cmd = NL80211_CMD_CHANNEL_SWITCH,
9479+
.doit = nl80211_channel_switch,
9480+
.policy = nl80211_policy,
9481+
.flags = GENL_ADMIN_PERM,
9482+
.internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9483+
NL80211_FLAG_NEED_RTNL,
9484+
},
93659485
};
93669486

93679487
static struct genl_multicast_group nl80211_mlme_mcgrp = {

net/wireless/rdev-ops.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,4 +923,16 @@ static inline void rdev_crit_proto_stop(struct cfg80211_registered_device *rdev,
923923
trace_rdev_return_void(&rdev->wiphy);
924924
}
925925

926+
static inline int rdev_channel_switch(struct cfg80211_registered_device *rdev,
927+
struct net_device *dev,
928+
struct cfg80211_csa_settings *params)
929+
{
930+
int ret;
931+
932+
trace_rdev_channel_switch(&rdev->wiphy, dev, params);
933+
ret = rdev->ops->channel_switch(&rdev->wiphy, dev, params);
934+
trace_rdev_return_int(&rdev->wiphy, ret);
935+
return ret;
936+
}
937+
926938
#endif /* __CFG80211_RDEV_OPS */

net/wireless/trace.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,6 +1841,39 @@ TRACE_EVENT(rdev_crit_proto_stop,
18411841
WIPHY_PR_ARG, WDEV_PR_ARG)
18421842
);
18431843

1844+
TRACE_EVENT(rdev_channel_switch,
1845+
TP_PROTO(struct wiphy *wiphy, struct net_device *netdev,
1846+
struct cfg80211_csa_settings *params),
1847+
TP_ARGS(wiphy, netdev, params),
1848+
TP_STRUCT__entry(
1849+
WIPHY_ENTRY
1850+
NETDEV_ENTRY
1851+
CHAN_DEF_ENTRY
1852+
__field(u16, counter_offset_beacon)
1853+
__field(u16, counter_offset_presp)
1854+
__field(bool, radar_required)
1855+
__field(bool, block_tx)
1856+
__field(u8, count)
1857+
),
1858+
TP_fast_assign(
1859+
WIPHY_ASSIGN;
1860+
NETDEV_ASSIGN;
1861+
CHAN_DEF_ASSIGN(&params->chandef);
1862+
__entry->counter_offset_beacon = params->counter_offset_beacon;
1863+
__entry->counter_offset_presp = params->counter_offset_presp;
1864+
__entry->radar_required = params->radar_required;
1865+
__entry->block_tx = params->block_tx;
1866+
__entry->count = params->count;
1867+
),
1868+
TP_printk(WIPHY_PR_FMT ", " NETDEV_PR_FMT ", " CHAN_DEF_PR_FMT
1869+
", block_tx: %d, count: %u, radar_required: %d"
1870+
", counter offsets (beacon/presp): %u/%u",
1871+
WIPHY_PR_ARG, NETDEV_PR_ARG, CHAN_DEF_PR_ARG,
1872+
__entry->block_tx, __entry->count, __entry->radar_required,
1873+
__entry->counter_offset_beacon,
1874+
__entry->counter_offset_presp)
1875+
);
1876+
18441877
/*************************************************************
18451878
* cfg80211 exported functions traces *
18461879
*************************************************************/

0 commit comments

Comments
 (0)