1 // SPDX-License-Identifier: GPL-2.0-only
3 * Scan related functions.
5 * Copyright (c) 2017-2019, Silicon Laboratories, Inc.
6 * Copyright (c) 2010, ST-Ericsson
8 #include <net/mac80211.h>
13 #include "hif_tx_mib.h"
15 static void __ieee80211_scan_completed_compat(struct ieee80211_hw
*hw
,
18 struct cfg80211_scan_info info
= {
22 ieee80211_scan_completed(hw
, &info
);
25 static int update_probe_tmpl(struct wfx_vif
*wvif
,
26 struct cfg80211_scan_request
*req
)
30 skb
= ieee80211_probereq_get(wvif
->wdev
->hw
, wvif
->vif
->addr
,
31 NULL
, 0, req
->ie_len
);
35 skb_put_data(skb
, req
->ie
, req
->ie_len
);
36 hif_set_template_frame(wvif
, skb
, HIF_TMPLT_PRBREQ
, 0);
41 static int send_scan_req(struct wfx_vif
*wvif
,
42 struct cfg80211_scan_request
*req
, int start_idx
)
45 struct ieee80211_channel
*ch_start
, *ch_cur
;
47 for (i
= start_idx
; i
< req
->n_channels
; i
++) {
48 ch_start
= req
->channels
[start_idx
];
49 ch_cur
= req
->channels
[i
];
50 WARN(ch_cur
->band
!= NL80211_BAND_2GHZ
, "band not supported");
51 if (ch_cur
->max_power
!= ch_start
->max_power
)
53 if ((ch_cur
->flags
^ ch_start
->flags
) & IEEE80211_CHAN_NO_IR
)
56 wfx_tx_lock_flush(wvif
->wdev
);
57 wvif
->scan_abort
= false;
58 reinit_completion(&wvif
->scan_complete
);
59 timeout
= hif_scan(wvif
, req
, start_idx
, i
- start_idx
);
62 ret
= wait_for_completion_timeout(&wvif
->scan_complete
, timeout
);
63 if (req
->channels
[start_idx
]->max_power
!= wvif
->vif
->bss_conf
.txpower
)
64 hif_set_output_power(wvif
, wvif
->vif
->bss_conf
.txpower
);
65 wfx_tx_unlock(wvif
->wdev
);
67 dev_notice(wvif
->wdev
->dev
, "scan timeout\n");
71 if (wvif
->scan_abort
) {
72 dev_notice(wvif
->wdev
->dev
, "scan abort\n");
79 * It is not really necessary to run scan request asynchronously. However,
80 * there is a bug in "iw scan" when ieee80211_scan_completed() is called before
81 * wfx_hw_scan() return
83 void wfx_hw_scan_work(struct work_struct
*work
)
85 struct wfx_vif
*wvif
= container_of(work
, struct wfx_vif
, scan_work
);
86 struct ieee80211_scan_request
*hw_req
= wvif
->scan_req
;
89 mutex_lock(&wvif
->scan_lock
);
90 mutex_lock(&wvif
->wdev
->conf_mutex
);
91 update_probe_tmpl(wvif
, &hw_req
->req
);
92 wfx_fwd_probe_req(wvif
, true);
95 ret
= send_scan_req(wvif
, &hw_req
->req
, chan_cur
);
98 } while (ret
> 0 && chan_cur
< hw_req
->req
.n_channels
);
99 mutex_unlock(&wvif
->wdev
->conf_mutex
);
100 mutex_unlock(&wvif
->scan_lock
);
101 __ieee80211_scan_completed_compat(wvif
->wdev
->hw
, ret
< 0);
104 int wfx_hw_scan(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
105 struct ieee80211_scan_request
*hw_req
)
107 struct wfx_vif
*wvif
= (struct wfx_vif
*)vif
->drv_priv
;
109 WARN_ON(hw_req
->req
.n_channels
> HIF_API_MAX_NB_CHANNELS
);
111 if (vif
->type
== NL80211_IFTYPE_AP
)
114 if (wvif
->state
== WFX_STATE_PRE_STA
)
117 wvif
->scan_req
= hw_req
;
118 schedule_work(&wvif
->scan_work
);
122 void wfx_cancel_hw_scan(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
124 struct wfx_vif
*wvif
= (struct wfx_vif
*)vif
->drv_priv
;
126 wvif
->scan_abort
= true;
130 void wfx_scan_complete(struct wfx_vif
*wvif
)
132 complete(&wvif
->scan_complete
);