Lines Matching +full:duration +full:- +full:us
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Off-channel operation helpers
8 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
11 * Copyright (C) 2019, 2022-2025 Intel Corporation
16 #include "driver-ops.h"
21 * the frames while we are doing off-channel work. This is optional
22 * because we *may* be doing work on-operating channel, and want our
23 * hardware unconditionally awake, but still let the AP send us normal frames.
27 struct ieee80211_local *local = sdata->local;
28 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
31 /* FIXME: what to do when local->pspolling is true? */
33 timer_delete_sync(&local->dynamic_ps_timer);
34 timer_delete_sync(&ifmgd->bcn_mon_timer);
35 timer_delete_sync(&ifmgd->conn_mon_timer);
37 wiphy_work_cancel(local->hw.wiphy, &local->dynamic_ps_enable_work);
39 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
41 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
42 ieee80211_hw_config(local, -1, IEEE80211_CONF_CHANGE_PS);
46 !ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
63 struct ieee80211_local *local = sdata->local;
65 if (!local->ps_sdata)
67 else if (local->hw.conf.dynamic_ps_timeout > 0) {
75 mod_timer(&local->dynamic_ps_timer, jiffies +
76 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
87 lockdep_assert_wiphy(local->hw.wiphy);
89 if (WARN_ON(!local->emulate_chanctx))
93 * notify the AP about us leaving the channel and stop all
101 ieee80211_stop_queues_by_reason(&local->hw, IEEE80211_MAX_QUEUE_MAP,
106 list_for_each_entry(sdata, &local->interfaces, list) {
110 if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE ||
111 sdata->vif.type == NL80211_IFTYPE_NAN)
114 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
115 set_bit(SDATA_STATE_OFFCHANNEL, &sdata->state);
118 if (sdata->vif.bss_conf.enable_beacon) {
120 &sdata->state);
121 sdata->vif.bss_conf.enable_beacon = false;
123 sdata, &sdata->deflink,
127 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
128 sdata->u.mgd.associated)
137 lockdep_assert_wiphy(local->hw.wiphy);
139 if (WARN_ON(!local->emulate_chanctx))
142 list_for_each_entry(sdata, &local->interfaces, list) {
143 if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE)
146 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
147 clear_bit(SDATA_STATE_OFFCHANNEL, &sdata->state);
153 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
154 sdata->u.mgd.associated)
158 &sdata->state)) {
159 sdata->vif.bss_conf.enable_beacon = true;
161 sdata, &sdata->deflink,
166 ieee80211_wake_queues_by_reason(&local->hw, IEEE80211_MAX_QUEUE_MAP,
174 if (roc->frame) {
175 cfg80211_mgmt_tx_status(&roc->sdata->wdev, roc->mgmt_tx_cookie,
176 roc->frame->data, roc->frame->len,
178 ieee80211_free_txskb(&roc->sdata->local->hw, roc->frame);
181 if (!roc->mgmt_tx_cookie)
182 cfg80211_remain_on_channel_expired(&roc->sdata->wdev,
183 roc->cookie, roc->chan,
186 cfg80211_tx_mgmt_expired(&roc->sdata->wdev,
187 roc->mgmt_tx_cookie,
188 roc->chan, GFP_KERNEL);
190 list_del(&roc->list);
200 lockdep_assert_wiphy(local->hw.wiphy);
202 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
205 if (!roc->started)
208 remaining = roc->start_time +
209 msecs_to_jiffies(roc->duration) -
216 if (roc->abort || roc->hw_begun || remaining <= 0)
233 wiphy_delayed_work_queue(local->hw.wiphy, &local->roc_work, dur);
240 if (WARN_ON(roc->notified))
243 roc->start_time = start_time;
244 roc->started = true;
246 if (roc->mgmt_tx_cookie) {
247 if (!WARN_ON(!roc->frame)) {
248 ieee80211_tx_skb_tid_band(roc->sdata, roc->frame, 7,
249 roc->chan->band);
250 roc->frame = NULL;
253 cfg80211_ready_on_channel(&roc->sdata->wdev, roc->cookie,
254 roc->chan, roc->req_duration,
258 roc->notified = true;
267 lockdep_assert_wiphy(local->hw.wiphy);
269 list_for_each_entry(roc, &local->roc_list, list) {
270 if (!roc->started)
273 roc->hw_begun = true;
274 ieee80211_handle_roc_started(roc, local->hw_roc_start_time);
282 local->hw_roc_start_time = jiffies;
286 wiphy_work_queue(hw->wiphy, &local->hw_roc_start);
296 lockdep_assert_wiphy(local->hw.wiphy);
298 if (WARN_ON(list_empty(&local->roc_list)))
301 roc = list_first_entry(&local->roc_list, struct ieee80211_roc_work,
304 if (WARN_ON(roc->started))
307 min_dur = roc->duration;
308 max_dur = roc->duration;
309 type = roc->type;
311 list_for_each_entry(tmp, &local->roc_list, list) {
314 if (tmp->sdata != roc->sdata || tmp->chan != roc->chan)
316 max_dur = max(tmp->duration, max_dur);
317 min_dur = min(tmp->duration, min_dur);
318 type = max(tmp->type, type);
321 if (local->ops->remain_on_channel) {
322 int ret = drv_remain_on_channel(local, roc->sdata, roc->chan,
326 wiphy_warn(local->hw.wiphy,
332 list_for_each_entry(tmp, &local->roc_list, list) {
333 if (tmp->sdata != roc->sdata ||
334 tmp->chan != roc->chan)
336 tmp->started = true;
337 tmp->abort = true;
339 wiphy_work_queue(local->hw.wiphy, &local->hw_roc_done);
344 list_for_each_entry(tmp, &local->roc_list, list) {
345 if (tmp->sdata != roc->sdata || tmp->chan != roc->chan)
347 tmp->started = true;
358 roc->on_channel = roc->chan == local->hw.conf.chandef.chan &&
359 local->hw.conf.chandef.width != NL80211_CHAN_WIDTH_5 &&
360 local->hw.conf.chandef.width != NL80211_CHAN_WIDTH_10;
365 if (!roc->on_channel) {
368 local->tmp_channel = roc->chan;
372 wiphy_delayed_work_queue(local->hw.wiphy, &local->roc_work,
376 list_for_each_entry(tmp, &local->roc_list, list) {
377 if (tmp->sdata != roc->sdata || tmp->chan != roc->chan)
380 tmp->on_channel = roc->on_channel;
390 lockdep_assert_wiphy(local->hw.wiphy);
392 if (list_empty(&local->roc_list)) {
398 if (local->in_reconfig)
401 roc = list_first_entry(&local->roc_list, struct ieee80211_roc_work,
404 if (WARN_ON_ONCE(roc->started))
407 if (local->ops->remain_on_channel) {
411 wiphy_delayed_work_queue(local->hw.wiphy, &local->roc_work,
425 if (!local->ops->remain_on_channel)
429 wiphy_work_flush(local->hw.wiphy, &local->hw_roc_start);
430 wiphy_work_flush(local->hw.wiphy, &local->hw_roc_done);
432 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
433 if (!roc->started)
436 if (!roc->hw_begun) {
438 roc->started = false;
454 lockdep_assert_wiphy(local->hw.wiphy);
456 if (WARN_ON(local->ops->remain_on_channel))
459 roc = list_first_entry_or_null(&local->roc_list,
464 if (!roc->started) {
465 WARN_ON(!local->emulate_chanctx);
468 on_channel = roc->on_channel;
472 /* careful - roc pointer became invalid during recalc */
477 local->tmp_channel = NULL;
493 lockdep_assert_wiphy(local->hw.wiphy);
503 lockdep_assert_wiphy(local->hw.wiphy);
517 wiphy_work_queue(hw->wiphy, &local->hw_roc_done);
529 if (WARN_ON(!cur_roc->started))
533 * we can only combine if the older one had a longer duration
535 if (!cur_roc->hw_begun && new_roc->duration > cur_roc->duration)
538 remaining = cur_roc->start_time +
539 msecs_to_jiffies(cur_roc->duration) -
543 if (new_roc->duration > jiffies_to_msecs(remaining))
547 list_add(&new_roc->list, &cur_roc->list);
551 * struct that runs once the driver notifies us of the beginning
553 if (cur_roc->hw_begun) {
554 new_roc->hw_begun = true;
564 unsigned int duration, u64 *cookie,
573 lockdep_assert_wiphy(local->hw.wiphy);
575 if (channel->freq_offset)
577 return -EOPNOTSUPP;
579 if (!local->emulate_chanctx && !local->ops->remain_on_channel)
580 return -EOPNOTSUPP;
584 return -ENOMEM;
587 * If the duration is zero, then the driver
591 * TODO: cancel the off-channel operation
595 if (!duration)
596 duration = 10;
598 roc->chan = channel;
599 roc->duration = duration;
600 roc->req_duration = duration;
601 roc->frame = txskb;
602 roc->type = type;
603 roc->sdata = sdata;
610 roc->cookie = ieee80211_mgmt_tx_cookie(local);
611 *cookie = roc->cookie;
613 roc->mgmt_tx_cookie = *cookie;
616 req = wiphy_dereference(local->hw.wiphy, local->scan_req);
619 if (list_empty(&local->roc_list) &&
620 !local->scanning && !ieee80211_is_radar_required(local, req)) {
622 if (!local->ops->remain_on_channel) {
623 list_add_tail(&roc->list, &local->roc_list);
624 wiphy_delayed_work_queue(local->hw.wiphy,
625 &local->roc_work, 0);
631 duration, type);
636 roc->started = true;
637 list_add_tail(&roc->list, &local->roc_list);
645 list_for_each_entry(tmp, &local->roc_list, list) {
646 if (tmp->chan != channel || tmp->sdata != sdata)
653 if (!tmp->started) {
654 list_add(&roc->list, &tmp->list);
662 if (!local->ops->remain_on_channel) {
663 /* If there's no hardware remain-on-channel, and
664 * doing so won't push us over the maximum r-o-c
673 u32 elapsed = jiffies_to_msecs(now - tmp->start_time);
674 struct wiphy *wiphy = local->hw.wiphy;
675 u32 max_roc = wiphy->max_remain_on_channel_duration;
677 if (elapsed + roc->duration > max_roc) {
682 list_add(&roc->list, &tmp->list);
684 roc->on_channel = tmp->on_channel;
702 list_add_tail(&roc->list, &local->roc_list);
709 unsigned int duration, u64 *cookie)
712 struct ieee80211_local *local = sdata->local;
714 lockdep_assert_wiphy(local->hw.wiphy);
717 duration, cookie, NULL,
727 lockdep_assert_wiphy(local->hw.wiphy);
730 return -ENOENT;
732 wiphy_work_flush(local->hw.wiphy, &local->hw_roc_start);
734 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
735 if (!mgmt_tx && roc->cookie != cookie)
737 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
745 return -ENOENT;
748 if (!found->started) {
753 if (local->ops->remain_on_channel) {
754 ret = drv_cancel_remain_on_channel(local, roc->sdata);
774 wiphy_work_cancel(local->hw.wiphy, &local->hw_roc_done);
778 * cancel them all - we should wait for as much time as needed
781 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
782 if (!roc->started)
789 /* that really must not happen - it was started */
795 found->abort = true;
796 wiphy_delayed_work_queue(local->hw.wiphy, &local->roc_work, 0);
808 struct ieee80211_local *local = sdata->local;
817 struct ieee80211_local *local = sdata->local;
820 const struct ieee80211_mgmt *mgmt = (void *)params->buf;
823 int link_id = -1;
828 lockdep_assert_wiphy(local->hw.wiphy);
830 if (params->dont_wait_for_ack)
836 if (params->no_cck)
839 switch (sdata->vif.type) {
841 if (!sdata->vif.cfg.ibss_joined)
846 if (ieee80211_vif_is_mesh(&sdata->vif) &&
847 !sdata->u.mesh.mesh_id_len)
854 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
855 !ieee80211_vif_is_mesh(&sdata->vif) &&
856 !sdata->bss->active)
860 sta = sta_info_get_bss(sdata, mgmt->da);
861 mlo_sta = sta && sta->sta.mlo;
863 if (!ieee80211_is_action(mgmt->frame_control) ||
864 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC ||
865 mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED ||
866 mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
873 return -ENOLINK;
875 if (params->link_id >= 0 &&
876 !(sta->sta.valid_links & BIT(params->link_id))) {
878 return -ENOLINK;
880 link_id = params->link_id;
885 if (!sdata->u.mgd.associated ||
886 (params->offchan && params->wait &&
887 local->ops->remain_on_channel &&
888 memcmp(sdata->vif.cfg.ap_addr, mgmt->bssid, ETH_ALEN))) {
890 } else if (sdata->u.mgd.associated &&
891 ether_addr_equal(sdata->vif.cfg.ap_addr, mgmt->da)) {
892 sta = sta_info_get_bss(sdata, mgmt->da);
893 mlo_sta = sta && sta->sta.mlo;
902 return -EOPNOTSUPP;
908 if (need_offchan && !params->chan)
909 return -EINVAL;
912 if (!params->chan && mlo_sta) {
914 } else if (sdata->vif.type == NL80211_IFTYPE_NAN) {
922 for (i = 0; i < ARRAY_SIZE(sdata->vif.link_conf); i++) {
925 conf = rcu_dereference(sdata->vif.link_conf[i]);
929 chanctx_conf = rcu_dereference(conf->chanctx_conf);
933 if (mlo_sta && params->chan == chanctx_conf->def.chan &&
934 ether_addr_equal(sdata->vif.addr, mgmt->sa)) {
939 if (ether_addr_equal(conf->addr, mgmt->sa)) {
944 if (sdata->vif.valid_links &&
945 params->link_id >= 0 && params->link_id == i &&
946 params->chan == chanctx_conf->def.chan)
956 need_offchan = params->chan &&
957 (params->chan !=
958 chanctx_conf->def.chan);
965 if (need_offchan && !params->offchan) {
966 ret = -EBUSY;
970 skb = dev_alloc_skb(local->hw.extra_tx_headroom + params->len);
972 ret = -ENOMEM;
975 skb_reserve(skb, local->hw.extra_tx_headroom);
977 data = skb_put_data(skb, params->buf, params->len);
980 if (sdata->vif.bss_conf.csa_active &&
981 (sdata->vif.type == NL80211_IFTYPE_AP ||
982 sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
983 sdata->vif.type == NL80211_IFTYPE_ADHOC) &&
984 params->n_csa_offsets) {
990 if (sdata->vif.type == NL80211_IFTYPE_AP)
991 beacon = rcu_dereference(sdata->deflink.u.ap.beacon);
992 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
993 beacon = rcu_dereference(sdata->u.ibss.presp);
994 else if (ieee80211_vif_is_mesh(&sdata->vif))
995 beacon = rcu_dereference(sdata->u.mesh.beacon);
998 for (i = 0; i < params->n_csa_offsets; i++)
999 data[params->csa_offsets[i]] =
1000 beacon->cntdwn_current_counter;
1005 IEEE80211_SKB_CB(skb)->flags = flags;
1006 IEEE80211_SKB_CB(skb)->control.flags |= IEEE80211_TX_CTRL_DONT_USE_RATE_MASK;
1008 skb->dev = sdata->dev;
1010 if (!params->dont_wait_for_ack) {
1020 /* Assign a dummy non-zero cookie, it's not sent to
1023 * mgmt-tx from remain-on-channel.
1034 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
1036 if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
1037 IEEE80211_SKB_CB(skb)->hw_queue =
1038 local->hw.offchannel_tx_hw_queue;
1041 ret = ieee80211_start_roc_work(local, sdata, params->chan,
1042 params->wait, cookie, skb,
1045 ieee80211_free_txskb(&local->hw, skb);
1060 wiphy_work_init(&local->hw_roc_start, ieee80211_hw_roc_start);
1061 wiphy_work_init(&local->hw_roc_done, ieee80211_hw_roc_done);
1062 wiphy_delayed_work_init(&local->roc_work, ieee80211_roc_work);
1063 INIT_LIST_HEAD(&local->roc_list);
1072 lockdep_assert_wiphy(local->hw.wiphy);
1074 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
1075 if (sdata && roc->sdata != sdata)
1078 if (roc->started) {
1079 if (local->ops->remain_on_channel) {
1081 drv_cancel_remain_on_channel(local, roc->sdata);
1084 roc->abort = true;