2 * Copyright (c) 2014-2016 Qualcomm Atheros, Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #define P2P_WILDCARD_SSID "DIRECT-"
21 #define P2P_DMG_SOCIAL_CHANNEL 2
22 #define P2P_SEARCH_DURATION_MS 500
23 #define P2P_DEFAULT_BI 100
25 bool wil_p2p_is_social_scan(struct cfg80211_scan_request *request)
27 return (request->n_channels == 1) &&
28 (request->channels[0]->hw_value == P2P_DMG_SOCIAL_CHANNEL);
31 void wil_p2p_discovery_timer_fn(ulong x)
33 struct wil6210_priv *wil = (void *)x;
35 wil_dbg_misc(wil, "%s\n", __func__);
37 schedule_work(&wil->p2p.discovery_expired_work);
40 int wil_p2p_search(struct wil6210_priv *wil,
41 struct cfg80211_scan_request *request)
44 struct wil_p2p_info *p2p = &wil->p2p;
46 wil_dbg_misc(wil, "%s: channel %d\n",
47 __func__, P2P_DMG_SOCIAL_CHANNEL);
49 mutex_lock(&wil->mutex);
51 if (p2p->discovery_started) {
52 wil_err(wil, "%s: search failed. discovery already ongoing\n",
58 rc = wmi_p2p_cfg(wil, P2P_DMG_SOCIAL_CHANNEL, P2P_DEFAULT_BI);
60 wil_err(wil, "%s: wmi_p2p_cfg failed\n", __func__);
64 rc = wmi_set_ssid(wil, strlen(P2P_WILDCARD_SSID), P2P_WILDCARD_SSID);
66 wil_err(wil, "%s: wmi_set_ssid failed\n", __func__);
70 /* Set application IE to probe request and probe response */
71 rc = wmi_set_ie(wil, WMI_FRAME_PROBE_REQ,
72 request->ie_len, request->ie);
74 wil_err(wil, "%s: wmi_set_ie(WMI_FRAME_PROBE_REQ) failed\n",
79 /* supplicant doesn't provide Probe Response IEs. As a workaround -
80 * re-use Probe Request IEs
82 rc = wmi_set_ie(wil, WMI_FRAME_PROBE_RESP,
83 request->ie_len, request->ie);
85 wil_err(wil, "%s: wmi_set_ie(WMI_FRAME_PROBE_RESP) failed\n",
90 rc = wmi_start_search(wil);
92 wil_err(wil, "%s: wmi_start_search failed\n", __func__);
96 p2p->discovery_started = 1;
97 INIT_WORK(&p2p->discovery_expired_work, wil_p2p_search_expired);
98 mod_timer(&p2p->discovery_timer,
99 jiffies + msecs_to_jiffies(P2P_SEARCH_DURATION_MS));
103 wmi_stop_discovery(wil);
106 mutex_unlock(&wil->mutex);
110 int wil_p2p_listen(struct wil6210_priv *wil, unsigned int duration,
111 struct ieee80211_channel *chan, u64 *cookie)
113 struct wil_p2p_info *p2p = &wil->p2p;
114 u8 channel = P2P_DMG_SOCIAL_CHANNEL;
120 channel = chan->hw_value;
122 wil_dbg_misc(wil, "%s: duration %d\n", __func__, duration);
124 mutex_lock(&wil->mutex);
126 if (p2p->discovery_started) {
127 wil_err(wil, "%s: discovery already ongoing\n", __func__);
132 rc = wmi_p2p_cfg(wil, channel, P2P_DEFAULT_BI);
134 wil_err(wil, "%s: wmi_p2p_cfg failed\n", __func__);
138 rc = wmi_set_ssid(wil, strlen(P2P_WILDCARD_SSID), P2P_WILDCARD_SSID);
140 wil_err(wil, "%s: wmi_set_ssid failed\n", __func__);
144 rc = wmi_start_listen(wil);
146 wil_err(wil, "%s: wmi_start_listen failed\n", __func__);
150 memcpy(&p2p->listen_chan, chan, sizeof(*chan));
151 *cookie = ++p2p->cookie;
153 p2p->discovery_started = 1;
154 INIT_WORK(&p2p->discovery_expired_work, wil_p2p_listen_expired);
155 mod_timer(&p2p->discovery_timer,
156 jiffies + msecs_to_jiffies(duration));
160 wmi_stop_discovery(wil);
163 mutex_unlock(&wil->mutex);
167 u8 wil_p2p_stop_discovery(struct wil6210_priv *wil)
169 struct wil_p2p_info *p2p = &wil->p2p;
170 u8 started = p2p->discovery_started;
172 if (p2p->discovery_started) {
173 del_timer_sync(&p2p->discovery_timer);
174 p2p->discovery_started = 0;
175 wmi_stop_discovery(wil);
181 int wil_p2p_cancel_listen(struct wil6210_priv *wil, u64 cookie)
183 struct wil_p2p_info *p2p = &wil->p2p;
186 mutex_lock(&wil->mutex);
188 if (cookie != p2p->cookie) {
189 wil_info(wil, "%s: Cookie mismatch: 0x%016llx vs. 0x%016llx\n",
190 __func__, p2p->cookie, cookie);
191 mutex_unlock(&wil->mutex);
195 started = wil_p2p_stop_discovery(wil);
197 mutex_unlock(&wil->mutex);
200 wil_err(wil, "%s: listen not started\n", __func__);
204 mutex_lock(&wil->p2p_wdev_mutex);
205 cfg80211_remain_on_channel_expired(wil->radio_wdev,
209 wil->radio_wdev = wil->wdev;
210 mutex_unlock(&wil->p2p_wdev_mutex);
214 void wil_p2p_listen_expired(struct work_struct *work)
216 struct wil_p2p_info *p2p = container_of(work,
217 struct wil_p2p_info, discovery_expired_work);
218 struct wil6210_priv *wil = container_of(p2p,
219 struct wil6210_priv, p2p);
222 wil_dbg_misc(wil, "%s()\n", __func__);
224 mutex_lock(&wil->mutex);
225 started = wil_p2p_stop_discovery(wil);
226 mutex_unlock(&wil->mutex);
229 mutex_lock(&wil->p2p_wdev_mutex);
230 cfg80211_remain_on_channel_expired(wil->radio_wdev,
234 wil->radio_wdev = wil->wdev;
235 mutex_unlock(&wil->p2p_wdev_mutex);
240 void wil_p2p_search_expired(struct work_struct *work)
242 struct wil_p2p_info *p2p = container_of(work,
243 struct wil_p2p_info, discovery_expired_work);
244 struct wil6210_priv *wil = container_of(p2p,
245 struct wil6210_priv, p2p);
248 wil_dbg_misc(wil, "%s()\n", __func__);
250 mutex_lock(&wil->mutex);
251 started = wil_p2p_stop_discovery(wil);
252 mutex_unlock(&wil->mutex);
255 struct cfg80211_scan_info info = {
259 mutex_lock(&wil->p2p_wdev_mutex);
260 cfg80211_scan_done(wil->scan_request, &info);
261 wil->scan_request = NULL;
262 wil->radio_wdev = wil->wdev;
263 mutex_unlock(&wil->p2p_wdev_mutex);
267 void wil_p2p_stop_radio_operations(struct wil6210_priv *wil)
269 struct wil_p2p_info *p2p = &wil->p2p;
270 struct cfg80211_scan_info info = {
274 lockdep_assert_held(&wil->mutex);
276 mutex_lock(&wil->p2p_wdev_mutex);
278 if (wil->radio_wdev != wil->p2p_wdev)
281 if (!p2p->discovery_started) {
282 /* Regular scan on the p2p device */
283 if (wil->scan_request &&
284 wil->scan_request->wdev == wil->p2p_wdev) {
285 cfg80211_scan_done(wil->scan_request, &info);
286 wil->scan_request = NULL;
291 /* Search or listen on p2p device */
292 mutex_unlock(&wil->p2p_wdev_mutex);
293 wil_p2p_stop_discovery(wil);
294 mutex_lock(&wil->p2p_wdev_mutex);
296 if (wil->scan_request) {
298 cfg80211_scan_done(wil->scan_request, &info);
299 wil->scan_request = NULL;
302 cfg80211_remain_on_channel_expired(wil->radio_wdev,
309 wil->radio_wdev = wil->wdev;
310 mutex_unlock(&wil->p2p_wdev_mutex);