blob: 22d9de81e08f5236965bfcd4fb80a8aabff29a66 [file] [log] [blame]
Arend van Spriel9f440b72013-02-08 15:53:36 +01001/*
2 * Copyright (c) 2012 Broadcom Corporation
3 *
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.
7 *
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 ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16#include <linux/slab.h>
17#include <linux/netdevice.h>
18#include <net/cfg80211.h>
19
20#include <brcmu_wifi.h>
21#include <brcmu_utils.h>
22#include <defs.h>
23#include <dhd.h>
24#include <dhd_dbg.h>
25#include "fwil.h"
26#include "p2p.h"
27#include "wl_cfg80211.h"
28
29/* parameters used for p2p escan */
30#define P2PAPI_SCAN_NPROBES 1
31#define P2PAPI_SCAN_DWELL_TIME_MS 80
32#define P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS 40
33#define P2PAPI_SCAN_HOME_TIME_MS 60
34#define P2PAPI_SCAN_NPROBS_TIME_MS 30
35#define P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS 100
36#define WL_SCAN_CONNECT_DWELL_TIME_MS 200
37#define WL_SCAN_JOIN_PROBE_INTERVAL_MS 20
38
39#define BRCMF_P2P_WILDCARD_SSID "DIRECT-"
40#define BRCMF_P2P_WILDCARD_SSID_LEN (sizeof(BRCMF_P2P_WILDCARD_SSID) - 1)
41
42#define SOCIAL_CHAN_1 1
43#define SOCIAL_CHAN_2 6
44#define SOCIAL_CHAN_3 11
45#define SOCIAL_CHAN_CNT 3
46#define AF_PEER_SEARCH_CNT 2
47
48/**
49 * struct brcmf_p2p_disc_st_le - set discovery state in firmware.
50 *
51 * @state: requested discovery state (see enum brcmf_p2p_disc_state).
52 * @chspec: channel parameter for %WL_P2P_DISC_ST_LISTEN state.
53 * @dwell: dwell time in ms for %WL_P2P_DISC_ST_LISTEN state.
54 */
55struct brcmf_p2p_disc_st_le {
56 u8 state;
57 __le16 chspec;
58 __le16 dwell;
59};
60
61/**
62 * enum brcmf_p2p_disc_state - P2P discovery state values
63 *
64 * @WL_P2P_DISC_ST_SCAN: P2P discovery with wildcard SSID and P2P IE.
65 * @WL_P2P_DISC_ST_LISTEN: P2P discovery off-channel for specified time.
66 * @WL_P2P_DISC_ST_SEARCH: P2P discovery with P2P wildcard SSID and P2P IE.
67 */
68enum brcmf_p2p_disc_state {
69 WL_P2P_DISC_ST_SCAN,
70 WL_P2P_DISC_ST_LISTEN,
71 WL_P2P_DISC_ST_SEARCH
72};
73
74/**
75 * struct brcmf_p2p_scan_le - P2P specific scan request.
76 *
77 * @type: type of scan method requested (values: 'E' or 'S').
78 * @reserved: reserved (ignored).
79 * @eparams: parameters used for type 'E'.
80 * @sparams: parameters used for type 'S'.
81 */
82struct brcmf_p2p_scan_le {
83 u8 type;
84 u8 reserved[3];
85 union {
86 struct brcmf_escan_params_le eparams;
87 struct brcmf_scan_params_le sparams;
88 };
89};
90
91static struct brcmf_cfg80211_vif *p2p_discover_vif(struct brcmf_p2p_info *p2p)
92{
93 return p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
94}
95
96/**
97 * brcmf_p2p_set_firmware() - prepare firmware for peer-to-peer operation.
98 *
99 * @p2p: P2P specific data.
100 */
101static int brcmf_p2p_set_firmware(struct brcmf_p2p_info *p2p)
102{
103 struct net_device *ndev = cfg_to_ndev(p2p->cfg);
104 u8 null_eth_addr[] = { 0, 0, 0, 0, 0, 0 };
105 s32 ret = 0;
106
107 brcmf_fil_iovar_int_set(netdev_priv(ndev), "apsta", 1);
108
109 /* In case of COB type, firmware has default mac address
110 * After Initializing firmware, we have to set current mac address to
111 * firmware for P2P device address
112 */
113 ret = brcmf_fil_iovar_data_set(netdev_priv(ndev), "p2p_da_override",
114 null_eth_addr, sizeof(null_eth_addr));
115 if (ret)
116 brcmf_err("failed to update device address ret %d\n", ret);
117
118 return ret;
119}
120
121/**
122 * brcmf_p2p_generate_bss_mac() - derive mac addresses for P2P.
123 *
124 * @p2p: P2P specific data.
125 *
126 * P2P needs mac addresses for P2P device and interface. These are
127 * derived from the primary net device, ie. the permanent ethernet
128 * address of the device.
129 */
130static void brcmf_p2p_generate_bss_mac(struct brcmf_p2p_info *p2p)
131{
132 struct net_device *ndev = cfg_to_ndev(p2p->cfg);
133
134 /* Generate the P2P Device Address. This consists of the device's
135 * primary MAC address with the locally administered bit set.
136 */
137 memcpy(p2p->dev_addr, ndev->dev_addr, ETH_ALEN);
138 p2p->dev_addr[0] |= 0x02;
139
140 /* Generate the P2P Interface Address. If the discovery and connection
141 * BSSCFGs need to simultaneously co-exist, then this address must be
142 * different from the P2P Device Address, but also locally administered.
143 */
144 memcpy(p2p->int_addr, p2p->dev_addr, ETH_ALEN);
145 p2p->int_addr[4] ^= 0x80;
146}
147
148/**
149 * brcmf_p2p_scan_is_p2p_request() - is cfg80211 scan request a P2P scan.
150 *
151 * @request: the scan request as received from cfg80211.
152 *
153 * returns true if one of the ssids in the request matches the
154 * P2P wildcard ssid; otherwise returns false.
155 */
156static bool brcmf_p2p_scan_is_p2p_request(struct cfg80211_scan_request *request)
157{
158 struct cfg80211_ssid *ssids = request->ssids;
159 int i;
160
161 for (i = 0; i < request->n_ssids; i++) {
162 if (ssids[i].ssid_len != BRCMF_P2P_WILDCARD_SSID_LEN)
163 continue;
164
165 brcmf_dbg(INFO, "comparing ssid \"%s\"", ssids[i].ssid);
166 if (!memcmp(BRCMF_P2P_WILDCARD_SSID, ssids[i].ssid,
167 BRCMF_P2P_WILDCARD_SSID_LEN))
168 return true;
169 }
170 return false;
171}
172
173/**
174 * brcmf_p2p_set_discover_state - set discover state in firmware.
175 *
176 * @ifp: low-level interface object.
177 * @state: discover state to set.
178 * @chanspec: channel parameters (for state @WL_P2P_DISC_ST_LISTEN only).
179 * @listen_ms: duration to listen (for state @WL_P2P_DISC_ST_LISTEN only).
180 */
181static s32 brcmf_p2p_set_discover_state(struct brcmf_if *ifp, u8 state,
182 u16 chanspec, u16 listen_ms)
183{
184 struct brcmf_p2p_disc_st_le discover_state;
185 s32 ret = 0;
186 brcmf_dbg(TRACE, "enter\n");
187
188 discover_state.state = state;
189 discover_state.chspec = cpu_to_le16(chanspec);
190 discover_state.dwell = cpu_to_le16(listen_ms);
191 ret = brcmf_fil_bsscfg_data_set(ifp, "p2p_state", &discover_state,
192 sizeof(discover_state));
193 return ret;
194}
195
196/**
197 * brcmf_p2p_discover_disable_search() - reset discover state.
198 *
199 * @p2p: P2P specific data.
200 *
201 * Reset the discover state to @WL_P2P_DISC_ST_SCAN. Returns 0 on success.
202 */
203static s32 brcmf_p2p_discover_disable_search(struct brcmf_p2p_info *p2p)
204{
205 struct brcmf_cfg80211_vif *vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
206 struct brcmf_p2p_disc_st_le discovery_mode;
207 int ret;
208
209 /*
210 * vif presence indicates discovery is initialized.
211 */
212 if (!vif)
213 return -ENODEV;
214
215 ret = brcmf_fil_bsscfg_data_get(vif->ifp, "p2p_state",
216 &discovery_mode,
217 sizeof(discovery_mode));
218 if (!ret && discovery_mode.state != WL_P2P_DISC_ST_SCAN)
219 ret = brcmf_p2p_set_discover_state(vif->ifp,
220 WL_P2P_DISC_ST_SCAN, 0, 0);
221 return ret;
222}
223
224/**
225 * brcmf_p2p_init_discovery() - enable discovery in the firmware.
226 *
227 * @p2p: P2P specific data.
228 *
229 * Configures the firmware to allow P2P peer discovery. Creates the
230 * virtual interface and consequently the P2P device for it.
231 */
232static s32 brcmf_p2p_init_discovery(struct brcmf_p2p_info *p2p)
233{
234 struct net_device *ndev = cfg_to_ndev(p2p->cfg);
235 struct brcmf_cfg80211_vif *vif;
236 struct brcmf_if *ifp;
237 struct p2p_bss *bss_dev;
238 s32 index;
239 s32 ret;
240
241 brcmf_dbg(TRACE, "enter\n");
242
243 bss_dev = &p2p->bss_idx[P2PAPI_BSSCFG_DEVICE];
244 if (bss_dev->vif != NULL) {
245 brcmf_dbg(INFO, "do nothing, already initialized\n");
246 return 0;
247 }
248
249 /* Enable P2P Discovery in the firmware */
250 ret = brcmf_fil_iovar_int_set(netdev_priv(ndev), "p2p_disc", 1);
251 if (ret < 0) {
252 brcmf_err("set discover error\n");
253 return ret;
254 }
255
256 /* obtain bsscfg index for P2P discovery */
257 ret = brcmf_fil_iovar_int_get(netdev_priv(ndev), "p2p_dev", &index);
258 if (ret < 0) {
259 brcmf_err("retrieving discover bsscfg index failed\n");
260 return ret;
261 }
262
263 /*
264 * need brcmf_if for setting the discovery state.
265 */
266 ifp = kzalloc(sizeof(*vif->ifp), GFP_KERNEL);
267 if (!ifp) {
268 brcmf_err("could not create discovery if\n");
269 return -ENOMEM;
270 }
271
272 /* set required fields */
273 ifp->drvr = p2p->cfg->pub;
274 ifp->ifidx = 0;
275 ifp->bssidx = index;
276
277 /* Set the initial discovery state to SCAN */
278 ret = brcmf_p2p_set_discover_state(ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
279
280 if (ret != 0) {
281 brcmf_err("unable to set WL_P2P_DISC_ST_SCAN\n");
282 (void)brcmf_fil_iovar_int_set(netdev_priv(ndev), "p2p_disc", 0);
283 kfree(ifp);
284 return ret;
285 }
286
287 /* create a vif for it */
288 vif = brcmf_alloc_vif(p2p->cfg, NULL, NL80211_IFTYPE_P2P_DEVICE, false);
289 if (IS_ERR(vif)) {
290 brcmf_err("could not create discovery vif\n");
291 kfree(ifp);
292 return PTR_ERR(vif);
293 }
294
295 vif->ifp = ifp;
296 ifp->vif = vif;
297 bss_dev->vif = vif;
298
299 return 0;
300}
301
302/**
303 * brcmf_p2p_deinit_discovery() - disable P2P device discovery.
304 *
305 * @p2p: P2P specific data.
306 *
307 * Resets the discovery state and disables it in firmware. The virtual
308 * interface and P2P device are freed.
309 */
310static s32 brcmf_p2p_deinit_discovery(struct brcmf_p2p_info *p2p)
311{
312 struct net_device *ndev = cfg_to_ndev(p2p->cfg);
313 struct brcmf_if *ifp;
314 struct p2p_bss *bss_dev;
315 brcmf_dbg(TRACE, "enter\n");
316
317 bss_dev = &p2p->bss_idx[P2PAPI_BSSCFG_DEVICE];
318 if (bss_dev->vif == NULL) {
319 brcmf_err("do nothing, not initialized\n");
320 return -EINVAL;
321 }
322
323 ifp = bss_dev->vif->ifp;
324
325 /* Set the discovery state to SCAN */
326 (void)brcmf_p2p_set_discover_state(ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
327
328 /* Disable P2P discovery in the firmware */
329 (void)brcmf_fil_iovar_int_set(netdev_priv(ndev), "p2p_disc", 0);
330
331 /* remove discovery interface */
332 brcmf_free_vif(bss_dev->vif);
333 bss_dev->vif = NULL;
334 kfree(ifp);
335
336 return 0;
337}
338
339/**
340 * brcmf_p2p_enable_discovery() - initialize and configure discovery.
341 *
342 * @p2p: P2P specific data.
343 * @ie: buffer containing information elements.
344 * @ie_len: length of @ie buffer.
345 *
346 * Initializes the discovery device and configure the virtual interface.
347 */
348static int brcmf_p2p_enable_discovery(struct brcmf_p2p_info *p2p,
349 const u8 *ie, u32 ie_len)
350{
351 struct brcmf_cfg80211_vif *vif;
352 s32 ret = 0;
353
354 brcmf_dbg(TRACE, "enter\n");
355 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
356 if (vif) {
357 brcmf_dbg(INFO,
358 "DISCOVERY init already done, just process IE\n");
359 goto set_ie;
360 }
361
362 ret = brcmf_p2p_init_discovery(p2p);
363 if (ret < 0) {
364 brcmf_err("init discovery error %d\n", ret);
365 goto exit;
366 }
367
368 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
369
370 /*
371 * Set wsec to any non-zero value in the discovery bsscfg
372 * to ensure our P2P probe responses have the privacy bit
373 * set in the 802.11 WPA IE. Some peer devices may not
374 * initiate WPS with us if this bit is not set.
375 */
376 ret = brcmf_fil_bsscfg_int_set(vif->ifp, "wsec", AES_ENABLED);
377 if (ret < 0)
378 brcmf_err("wsec error %d\n", ret);
379
380set_ie:
381 if (ie_len) {
382 ret = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBREQ_FLAG,
383 ie, ie_len);
384
385 if (ret < 0) {
386 brcmf_err("set probreq ie occurs error %d\n", ret);
387 goto exit;
388 }
389 }
390exit:
391 return ret;
392}
393
394/*
395 * brcmf_p2p_escan() - initiate a P2P scan.
396 *
397 * @p2p: P2P specific data.
398 * @num_chans: number of channels to scan.
399 * @chanspecs: channel parameters for @num_chans channels.
400 * @search_state: P2P discover state to use.
401 * @action: scan action to pass to firmware.
402 * @bss_type: type of P2P bss.
403 */
404static s32 brcmf_p2p_escan(struct brcmf_p2p_info *p2p, u32 num_chans,
405 u16 chanspecs[], s32 search_state, u16 action,
406 enum p2p_bss_type bss_type)
407{
408 s32 ret = 0;
409 s32 memsize = offsetof(struct brcmf_p2p_scan_le,
410 eparams.params_le.channel_list);
411 s32 nprobes;
412 s32 active;
413 u32 i;
414 u8 *memblk;
415 struct brcmf_cfg80211_vif *vif;
416 struct brcmf_p2p_scan_le *p2p_params;
417 struct brcmf_scan_params_le *sparams;
418 struct brcmf_ssid ssid;
419
420 /* add padding if uneven */
421 if (num_chans % 2)
422 memsize += sizeof(__le16);
423 memsize += num_chans * sizeof(__le16);
424 memblk = kzalloc(memsize, GFP_KERNEL);
425 if (!memblk)
426 return -ENOMEM;
427
428 vif = p2p->bss_idx[bss_type].vif;
429 if (vif == NULL) {
430 brcmf_err("no vif for bss type %d\n", bss_type);
431 ret = -EINVAL;
432 goto exit;
433 }
434
435 switch (search_state) {
436 case WL_P2P_DISC_ST_SEARCH:
437 /*
438 * If we in SEARCH STATE, we don't need to set SSID explictly
439 * because dongle use P2P WILDCARD internally by default
440 */
441 /* use null ssid */
442 ssid.SSID_len = 0;
443 memset(ssid.SSID, 0, sizeof(ssid.SSID));
444 break;
445 case WL_P2P_DISC_ST_SCAN:
446 /*
447 * wpa_supplicant has p2p_find command with type social or
448 * progressive. For progressive, we need to set the ssid to
449 * P2P WILDCARD because we just do broadcast scan unless
450 * setting SSID.
451 */
452 ssid.SSID_len = BRCMF_P2P_WILDCARD_SSID_LEN;
453 memcpy(ssid.SSID, BRCMF_P2P_WILDCARD_SSID, ssid.SSID_len);
454 break;
455 default:
456 brcmf_err(" invalid search state %d\n", search_state);
457 ret = -EINVAL;
458 goto exit;
459 }
460
461 brcmf_p2p_set_discover_state(vif->ifp, search_state, 0, 0);
462
463 /*
464 * set p2p scan parameters.
465 */
466 p2p_params = (struct brcmf_p2p_scan_le *)memblk;
467 p2p_params->type = 'E';
468
469 /* determine the scan engine parameters */
470 sparams = &p2p_params->eparams.params_le;
471 sparams->bss_type = DOT11_BSSTYPE_ANY;
472 if (p2p->cfg->active_scan)
473 sparams->scan_type = 0;
474 else
475 sparams->scan_type = 1;
476
477 memset(&sparams->bssid, 0xFF, ETH_ALEN);
478 if (ssid.SSID_len)
479 memcpy(sparams->ssid_le.SSID, ssid.SSID, ssid.SSID_len);
480 sparams->ssid_le.SSID_len = cpu_to_le32(ssid.SSID_len);
481 sparams->home_time = cpu_to_le32(P2PAPI_SCAN_HOME_TIME_MS);
482
483 /*
484 * SOCIAL_CHAN_CNT + 1 takes care of the Progressive scan
485 * supported by the supplicant.
486 */
487 if (num_chans == SOCIAL_CHAN_CNT || num_chans == (SOCIAL_CHAN_CNT + 1))
488 active = P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS;
489 else if (num_chans == AF_PEER_SEARCH_CNT)
490 active = P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS;
491 else if (wl_get_vif_state_all(p2p->cfg, BRCMF_VIF_STATUS_CONNECTED))
492 active = -1;
493 else
494 active = P2PAPI_SCAN_DWELL_TIME_MS;
495
496 /* Override scan params to find a peer for a connection */
497 if (num_chans == 1) {
498 active = WL_SCAN_CONNECT_DWELL_TIME_MS;
499 /* XXX WAR to sync with presence period of VSDB GO.
500 * send probe request more frequently
501 */
502 nprobes = active / WL_SCAN_JOIN_PROBE_INTERVAL_MS;
503 } else {
504 nprobes = active / P2PAPI_SCAN_NPROBS_TIME_MS;
505 }
506
507 if (nprobes <= 0)
508 nprobes = 1;
509
510 brcmf_dbg(INFO, "nprobes # %d, active_time %d\n", nprobes, active);
511 sparams->active_time = cpu_to_le32(active);
512 sparams->nprobes = cpu_to_le32(nprobes);
513 sparams->passive_time = cpu_to_le32(-1);
514 sparams->channel_num = cpu_to_le32(num_chans &
515 BRCMF_SCAN_PARAMS_COUNT_MASK);
516 for (i = 0; i < num_chans; i++)
517 sparams->channel_list[i] = cpu_to_le16(chanspecs[i]);
518
519 /* set the escan specific parameters */
520 p2p_params->eparams.version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION);
521 p2p_params->eparams.action = cpu_to_le16(action);
522 p2p_params->eparams.sync_id = cpu_to_le16(0x1234);
523 /* perform p2p scan on primary device */
524 ret = brcmf_fil_bsscfg_data_set(vif->ifp, "p2p_scan", memblk, memsize);
525 if (!ret)
526 set_bit(BRCMF_SCAN_STATUS_BUSY, &p2p->cfg->scan_status);
527exit:
528 kfree(memblk);
529 return ret;
530}
531
532/**
533 * brcmf_p2p_run_escan() - escan callback for peer-to-peer.
534 *
535 * @cfg: driver private data for cfg80211 interface.
536 * @ndev: net device for which scan is requested.
537 * @request: scan request from cfg80211.
538 * @action: scan action.
539 *
540 * Determines the P2P discovery state based to scan request parameters and
541 * validates the channels in the request.
542 */
543static s32 brcmf_p2p_run_escan(struct brcmf_cfg80211_info *cfg,
544 struct net_device *ndev,
545 struct cfg80211_scan_request *request,
546 u16 action)
547{
548 struct brcmf_p2p_info *p2p = &cfg->p2p;
549 s32 err = 0;
550 s32 search_state = WL_P2P_DISC_ST_SCAN;
551 struct brcmf_cfg80211_vif *vif;
552 struct net_device *dev = NULL;
553 int i, num_nodfs = 0;
554 u16 *chanspecs;
555
556 brcmf_dbg(TRACE, "enter\n");
557
558 if (!request) {
559 err = -EINVAL;
560 goto exit;
561 }
562
563 if (request->n_channels) {
564 chanspecs = kcalloc(request->n_channels, sizeof(*chanspecs),
565 GFP_KERNEL);
566 if (!chanspecs) {
567 err = -ENOMEM;
568 goto exit;
569 }
570 vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
571 if (vif)
572 dev = vif->wdev.netdev;
573 if (request->n_channels == 3 &&
574 request->channels[0]->hw_value == SOCIAL_CHAN_1 &&
575 request->channels[1]->hw_value == SOCIAL_CHAN_2 &&
576 request->channels[2]->hw_value == SOCIAL_CHAN_3) {
577 /* SOCIAL CHANNELS 1, 6, 11 */
578 search_state = WL_P2P_DISC_ST_SEARCH;
579 brcmf_dbg(INFO, "P2P SEARCH PHASE START\n");
580 } else if (dev != NULL && vif->mode == WL_MODE_AP) {
581 /* If you are already a GO, then do SEARCH only */
582 brcmf_dbg(INFO, "Already a GO. Do SEARCH Only\n");
583 search_state = WL_P2P_DISC_ST_SEARCH;
584 } else {
585 brcmf_dbg(INFO, "P2P SCAN STATE START\n");
586 }
587
588 /*
589 * no P2P scanning on passive or DFS channels.
590 */
591 for (i = 0; i < request->n_channels; i++) {
592 struct ieee80211_channel *chan = request->channels[i];
593
594 if (chan->flags & (IEEE80211_CHAN_RADAR |
595 IEEE80211_CHAN_PASSIVE_SCAN))
596 continue;
597
598 chanspecs[i] = channel_to_chanspec(chan);
599 brcmf_dbg(INFO, "%d: chan=%d, channel spec=%x\n",
600 num_nodfs, chan->hw_value, chanspecs[i]);
601 num_nodfs++;
602 }
603 err = brcmf_p2p_escan(p2p, num_nodfs, chanspecs, search_state,
604 action, P2PAPI_BSSCFG_DEVICE);
605 }
606exit:
607 if (err)
608 brcmf_err("error (%d)\n", err);
609 return err;
610}
611
612/**
613 * brcmf_p2p_scan_prep() - prepare scan based on request.
614 *
615 * @wiphy: wiphy device.
616 * @request: scan request from cfg80211.
617 *
618 * Prepare the scan appropriately for type of scan requested. Overrides the
619 * escan .run() callback for peer-to-peer scanning.
620 */
621int brcmf_p2p_scan_prep(struct wiphy *wiphy,
622 struct cfg80211_scan_request *request)
623{
624 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
625 struct brcmf_p2p_info *p2p = &cfg->p2p;
626 int err = 0;
627
628 if (brcmf_p2p_scan_is_p2p_request(request)) {
629 /* find my listen channel */
630 err = cfg80211_get_p2p_attr(request->ie, request->ie_len,
631 IEEE80211_P2P_ATTR_LISTEN_CHANNEL,
632 &p2p->listen_channel, 1);
633 if (err < 0)
634 return err;
635
636 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
637 brcmf_dbg(INFO, "P2P: GO_NEG_PHASE status cleared\n");
638
639 err = brcmf_p2p_enable_discovery(p2p, request->ie,
640 request->ie_len);
641
642 /*
643 * override .run_escan() callback.
644 */
645 cfg->escan_info.run = brcmf_p2p_run_escan;
646 } else {
647 /*
648 * legacy scan trigger
649 * So, we have to disable p2p discovery if p2p discovery is on
650 */
651 (void)brcmf_p2p_discover_disable_search(p2p);
652
653 /*
654 * clear p2p vendor ies for probe request set by
655 * previous p2p related scan(s).
656 */
657 if (p2p_discover_vif(p2p))
658 err = brcmf_vif_set_mgmt_ie(p2p_discover_vif(p2p),
659 BRCMF_VNDR_IE_PRBREQ_FLAG,
660 request->ie,
661 request->ie_len);
662 }
663 return err;
664}
665
666/**
667 * brcmf_p2p_attach() - attach for P2P.
668 *
669 * @cfg: driver private data for cfg80211 interface.
670 */
671void brcmf_p2p_attach(struct brcmf_cfg80211_info *cfg)
672{
673 struct brcmf_p2p_info *p2p;
674
675 p2p = &cfg->p2p;
676
677 p2p->cfg = cfg;
678 brcmf_p2p_set_firmware(p2p);
679 brcmf_p2p_generate_bss_mac(p2p);
680}
681
682/**
683 * brcmf_p2p_detach() - detach P2P.
684 *
685 * @p2p: P2P specific data.
686 */
687void brcmf_p2p_detach(struct brcmf_p2p_info *p2p)
688{
689 brcmf_p2p_deinit_discovery(p2p);
690 /* just set it all to zero */
691 memset(p2p, 0, sizeof(*p2p));
692}
693
694/**
695 * brcmf_p2p_add_vif() - create a new P2P virtual interface.
696 *
697 * @wiphy: wiphy device of new interface.
698 * @name: name of the new interface.
699 * @type: nl80211 interface type.
700 * @flags: TBD
701 * @params: TBD
702 *
703 * TODO: not yet supported.
704 */
705struct wireless_dev *brcmf_p2p_add_vif(struct wiphy *wiphy, const char *name,
706 enum nl80211_iftype type, u32 *flags,
707 struct vif_params *params)
708{
709 brcmf_err("enter - not supported yet\n");
710 brcmf_dbg(INFO, "adding vif \"%s\" (type=%d)\n", name, type);
711 return ERR_PTR(-EOPNOTSUPP);
712}
713
714/**
715 * brcmf_p2p_del_vif() - delete a P2P virtual interface.
716 *
717 * @wiphy: wiphy device of interface.
718 * @wdev: wireless device of interface.
719 *
720 * TODO: not yet supported.
721 */
722int brcmf_p2p_del_vif(struct wiphy *wiphy, struct wireless_dev *wdev)
723{
724 struct brcmf_cfg80211_vif *vif;
725
726 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
727 if (wdev->netdev)
728 brcmf_dbg(INFO, "deleting vif \"%s\"\n", wdev->netdev->name);
729 else
730 brcmf_dbg(INFO, "deleting vif \"wdev-%u\"\n",
731 wdev->identifier);
732 brcmf_err("enter - not supported yet\n");
733 return -EOPNOTSUPP;
734}