Skip to content

Commit 9588bbd

Browse files
Jouni Malinenlinvjw
authored andcommitted
cfg80211: add remain-on-channel command
Add new commands for requesting the driver to remain awake on a specified channel for the specified amount of time (and another command to cancel such an operation). This can be used to implement userspace-controlled off-channel operations, like Public Action frame exchange on another channel than the operation channel. The off-channel operation should behave similarly to scan, i.e. the local station (if associated) moves into power save mode to request the AP to buffer frames for it and then moves to the other channel to allow the off-channel operation to be completed. The duration parameter can be used to request enough time to receive a response from the target station. Signed-off-by: Jouni Malinen <jouni.malinen@atheros.com> Signed-off-by: Johannes Berg <johannes@sipsolutions.net> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent b203ffc commit 9588bbd

7 files changed

Lines changed: 368 additions & 15 deletions

File tree

‎include/linux/nl80211.h‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,31 @@
270270
* @NL80211_CMD_SET_WIPHY_NETNS: Set a wiphy's netns. Note that all devices
271271
* associated with this wiphy must be down and will follow.
272272
*
273+
* @NL80211_CMD_REMAIN_ON_CHANNEL: Request to remain awake on the specified
274+
* channel for the specified amount of time. This can be used to do
275+
* off-channel operations like transmit a Public Action frame and wait for
276+
* a response while being associated to an AP on another channel.
277+
* %NL80211_ATTR_WIPHY or %NL80211_ATTR_IFINDEX is used to specify which
278+
* radio is used. %NL80211_ATTR_WIPHY_FREQ is used to specify the
279+
* frequency for the operation and %NL80211_ATTR_WIPHY_CHANNEL_TYPE may be
280+
* optionally used to specify additional channel parameters.
281+
* %NL80211_ATTR_DURATION is used to specify the duration in milliseconds
282+
* to remain on the channel. This command is also used as an event to
283+
* notify when the requested duration starts (it may take a while for the
284+
* driver to schedule this time due to other concurrent needs for the
285+
* radio).
286+
* When called, this operation returns a cookie (%NL80211_ATTR_COOKIE)
287+
* that will be included with any events pertaining to this request;
288+
* the cookie is also used to cancel the request.
289+
* @NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL: This command can be used to cancel a
290+
* pending remain-on-channel duration if the desired operation has been
291+
* completed prior to expiration of the originally requested duration.
292+
* %NL80211_ATTR_WIPHY or %NL80211_ATTR_IFINDEX is used to specify the
293+
* radio. The %NL80211_ATTR_COOKIE attribute must be given as well to
294+
* uniquely identify the request.
295+
* This command is also used as an event to notify when a requested
296+
* remain-on-channel duration has expired.
297+
*
273298
* @NL80211_CMD_MAX: highest used command number
274299
* @__NL80211_CMD_AFTER_LAST: internal use
275300
*/
@@ -353,6 +378,9 @@ enum nl80211_commands {
353378
NL80211_CMD_DEL_PMKSA,
354379
NL80211_CMD_FLUSH_PMKSA,
355380

381+
NL80211_CMD_REMAIN_ON_CHANNEL,
382+
NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
383+
356384
/* add new commands above here */
357385

358386
/* used to define NL80211_CMD_MAX below */
@@ -606,6 +634,10 @@ enum nl80211_commands {
606634
* @NL80211_ATTR_MAX_NUM_PMKIDS: maximum number of PMKIDs a firmware can
607635
* cache, a wiphy attribute.
608636
*
637+
* @NL80211_ATTR_DURATION: Duration of an operation in milliseconds, u32.
638+
*
639+
* @NL80211_ATTR_COOKIE: Generic 64-bit cookie to identify objects.
640+
*
609641
* @NL80211_ATTR_MAX: highest attribute number currently defined
610642
* @__NL80211_ATTR_AFTER_LAST: internal use
611643
*/
@@ -743,6 +775,10 @@ enum nl80211_attrs {
743775
NL80211_ATTR_PMKID,
744776
NL80211_ATTR_MAX_NUM_PMKIDS,
745777

778+
NL80211_ATTR_DURATION,
779+
780+
NL80211_ATTR_COOKIE,
781+
746782
/* add attributes here, update the policy in nl80211.c */
747783

748784
__NL80211_ATTR_AFTER_LAST,

‎include/net/cfg80211.h‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,15 @@ struct cfg80211_pmksa {
988988
*
989989
* @dump_survey: get site survey information.
990990
*
991+
* @remain_on_channel: Request the driver to remain awake on the specified
992+
* channel for the specified duration to complete an off-channel
993+
* operation (e.g., public action frame exchange). When the driver is
994+
* ready on the requested channel, it must indicate this with an event
995+
* notification by calling cfg80211_ready_on_channel().
996+
* @cancel_remain_on_channel: Cancel an on-going remain-on-channel operation.
997+
* This allows the operation to be terminated prior to timeout based on
998+
* the duration value.
999+
*
9911000
* @testmode_cmd: run a test mode command
9921001
*
9931002
* @set_pmksa: Cache a PMKID for a BSSID. This is mostly useful for fullmac
@@ -1123,6 +1132,16 @@ struct cfg80211_ops {
11231132
struct cfg80211_pmksa *pmksa);
11241133
int (*flush_pmksa)(struct wiphy *wiphy, struct net_device *netdev);
11251134

1135+
int (*remain_on_channel)(struct wiphy *wiphy,
1136+
struct net_device *dev,
1137+
struct ieee80211_channel *chan,
1138+
enum nl80211_channel_type channel_type,
1139+
unsigned int duration,
1140+
u64 *cookie);
1141+
int (*cancel_remain_on_channel)(struct wiphy *wiphy,
1142+
struct net_device *dev,
1143+
u64 cookie);
1144+
11261145
/* some temporary stuff to finish wext */
11271146
int (*set_power_mgmt)(struct wiphy *wiphy, struct net_device *dev,
11281147
bool enabled, int timeout);
@@ -2147,5 +2166,33 @@ void cfg80211_roamed(struct net_device *dev, const u8 *bssid,
21472166
void cfg80211_disconnected(struct net_device *dev, u16 reason,
21482167
u8 *ie, size_t ie_len, gfp_t gfp);
21492168

2169+
/**
2170+
* cfg80211_ready_on_channel - notification of remain_on_channel start
2171+
* @dev: network device
2172+
* @cookie: the request cookie
2173+
* @chan: The current channel (from remain_on_channel request)
2174+
* @channel_type: Channel type
2175+
* @duration: Duration in milliseconds that the driver intents to remain on the
2176+
* channel
2177+
* @gfp: allocation flags
2178+
*/
2179+
void cfg80211_ready_on_channel(struct net_device *dev, u64 cookie,
2180+
struct ieee80211_channel *chan,
2181+
enum nl80211_channel_type channel_type,
2182+
unsigned int duration, gfp_t gfp);
2183+
2184+
/**
2185+
* cfg80211_remain_on_channel_expired - remain_on_channel duration expired
2186+
* @dev: network device
2187+
* @cookie: the request cookie
2188+
* @chan: The current channel (from remain_on_channel request)
2189+
* @channel_type: Channel type
2190+
* @gfp: allocation flags
2191+
*/
2192+
void cfg80211_remain_on_channel_expired(struct net_device *dev,
2193+
u64 cookie,
2194+
struct ieee80211_channel *chan,
2195+
enum nl80211_channel_type channel_type,
2196+
gfp_t gfp);
21502197

21512198
#endif /* __NET_CFG80211_H */

‎net/wireless/chan.c‎

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,44 +41,57 @@ rdev_fixed_channel(struct cfg80211_registered_device *rdev,
4141
return result;
4242
}
4343

44-
int rdev_set_freq(struct cfg80211_registered_device *rdev,
45-
struct wireless_dev *for_wdev,
44+
struct ieee80211_channel *
45+
rdev_freq_to_chan(struct cfg80211_registered_device *rdev,
4646
int freq, enum nl80211_channel_type channel_type)
4747
{
4848
struct ieee80211_channel *chan;
4949
struct ieee80211_sta_ht_cap *ht_cap;
50-
int result;
51-
52-
if (rdev_fixed_channel(rdev, for_wdev))
53-
return -EBUSY;
54-
55-
if (!rdev->ops->set_channel)
56-
return -EOPNOTSUPP;
5750

5851
chan = ieee80211_get_channel(&rdev->wiphy, freq);
5952

6053
/* Primary channel not allowed */
6154
if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
62-
return -EINVAL;
55+
return NULL;
6356

6457
if (channel_type == NL80211_CHAN_HT40MINUS &&
6558
chan->flags & IEEE80211_CHAN_NO_HT40MINUS)
66-
return -EINVAL;
59+
return NULL;
6760
else if (channel_type == NL80211_CHAN_HT40PLUS &&
6861
chan->flags & IEEE80211_CHAN_NO_HT40PLUS)
69-
return -EINVAL;
62+
return NULL;
7063

7164
ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap;
7265

7366
if (channel_type != NL80211_CHAN_NO_HT) {
7467
if (!ht_cap->ht_supported)
75-
return -EINVAL;
68+
return NULL;
7669

7770
if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) ||
7871
ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT)
79-
return -EINVAL;
72+
return NULL;
8073
}
8174

75+
return chan;
76+
}
77+
78+
int rdev_set_freq(struct cfg80211_registered_device *rdev,
79+
struct wireless_dev *for_wdev,
80+
int freq, enum nl80211_channel_type channel_type)
81+
{
82+
struct ieee80211_channel *chan;
83+
int result;
84+
85+
if (rdev_fixed_channel(rdev, for_wdev))
86+
return -EBUSY;
87+
88+
if (!rdev->ops->set_channel)
89+
return -EOPNOTSUPP;
90+
91+
chan = rdev_freq_to_chan(rdev, freq, channel_type);
92+
if (!chan)
93+
return -EINVAL;
94+
8295
result = rdev->ops->set_channel(&rdev->wiphy, chan, channel_type);
8396
if (result)
8497
return result;

‎net/wireless/core.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev);
374374
struct ieee80211_channel *
375375
rdev_fixed_channel(struct cfg80211_registered_device *rdev,
376376
struct wireless_dev *for_wdev);
377+
struct ieee80211_channel *
378+
rdev_freq_to_chan(struct cfg80211_registered_device *rdev,
379+
int freq, enum nl80211_channel_type channel_type);
377380
int rdev_set_freq(struct cfg80211_registered_device *rdev,
378381
struct wireless_dev *for_wdev,
379382
int freq, enum nl80211_channel_type channel_type);

‎net/wireless/mlme.c‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,3 +680,30 @@ void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
680680
}
681681
}
682682
}
683+
684+
void cfg80211_ready_on_channel(struct net_device *dev, u64 cookie,
685+
struct ieee80211_channel *chan,
686+
enum nl80211_channel_type channel_type,
687+
unsigned int duration, gfp_t gfp)
688+
{
689+
struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
690+
struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
691+
692+
nl80211_send_remain_on_channel(rdev, dev, cookie, chan, channel_type,
693+
duration, gfp);
694+
}
695+
EXPORT_SYMBOL(cfg80211_ready_on_channel);
696+
697+
void cfg80211_remain_on_channel_expired(struct net_device *dev,
698+
u64 cookie,
699+
struct ieee80211_channel *chan,
700+
enum nl80211_channel_type channel_type,
701+
gfp_t gfp)
702+
{
703+
struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
704+
struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
705+
706+
nl80211_send_remain_on_channel_cancel(rdev, dev, cookie, chan,
707+
channel_type, gfp);
708+
}
709+
EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);

0 commit comments

Comments
 (0)