brcmfmac: Use role from wdev on AP commands and fix stop_ap.
[deliverable/linux.git] / drivers / net / wireless / brcm80211 / brcmfmac / p2p.c
CommitLineData
9f440b7b
AS
1/*
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"
d3c0b633 26#include "fwil_types.h"
9f440b7b
AS
27#include "p2p.h"
28#include "wl_cfg80211.h"
29
30/* parameters used for p2p escan */
31#define P2PAPI_SCAN_NPROBES 1
32#define P2PAPI_SCAN_DWELL_TIME_MS 80
33#define P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS 40
34#define P2PAPI_SCAN_HOME_TIME_MS 60
35#define P2PAPI_SCAN_NPROBS_TIME_MS 30
36#define P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS 100
37#define WL_SCAN_CONNECT_DWELL_TIME_MS 200
38#define WL_SCAN_JOIN_PROBE_INTERVAL_MS 20
39
40#define BRCMF_P2P_WILDCARD_SSID "DIRECT-"
41#define BRCMF_P2P_WILDCARD_SSID_LEN (sizeof(BRCMF_P2P_WILDCARD_SSID) - 1)
42
43#define SOCIAL_CHAN_1 1
44#define SOCIAL_CHAN_2 6
45#define SOCIAL_CHAN_3 11
46#define SOCIAL_CHAN_CNT 3
47#define AF_PEER_SEARCH_CNT 2
48
d3c0b633
AS
49#define BRCMF_SCB_TIMEOUT_VALUE 20
50
e6da3400
HM
51#define P2P_VER 9 /* P2P version: 9=WiFi P2P v1.0 */
52#define P2P_PUB_AF_CATEGORY 0x04
53#define P2P_PUB_AF_ACTION 0x09
54#define P2P_AF_CATEGORY 0x7f
55#define P2P_OUI "\x50\x6F\x9A" /* P2P OUI */
56#define P2P_OUI_LEN 3 /* P2P OUI length */
57
18e2f61d
HM
58/* Action Frame Constants */
59#define DOT11_ACTION_HDR_LEN 2 /* action frame category + action */
60#define DOT11_ACTION_CAT_OFF 0 /* category offset */
61#define DOT11_ACTION_ACT_OFF 1 /* action offset */
62
63#define P2P_AF_DWELL_TIME 200
64#define P2P_AF_MIN_DWELL_TIME 100
65#define P2P_AF_MED_DWELL_TIME 400
66#define P2P_AF_LONG_DWELL_TIME 1000
67#define P2P_AF_TX_MAX_RETRY 5
68#define P2P_AF_MAX_WAIT_TIME 2000
69#define P2P_INVALID_CHANNEL -1
70#define P2P_CHANNEL_SYNC_RETRY 5
71#define P2P_AF_FRM_SCAN_MAX_WAIT 1500
72
e6da3400
HM
73/* WiFi P2P Public Action Frame OUI Subtypes */
74#define P2P_PAF_GON_REQ 0 /* Group Owner Negotiation Req */
75#define P2P_PAF_GON_RSP 1 /* Group Owner Negotiation Rsp */
76#define P2P_PAF_GON_CONF 2 /* Group Owner Negotiation Confirm */
77#define P2P_PAF_INVITE_REQ 3 /* P2P Invitation Request */
78#define P2P_PAF_INVITE_RSP 4 /* P2P Invitation Response */
79#define P2P_PAF_DEVDIS_REQ 5 /* Device Discoverability Request */
80#define P2P_PAF_DEVDIS_RSP 6 /* Device Discoverability Response */
81#define P2P_PAF_PROVDIS_REQ 7 /* Provision Discovery Request */
82#define P2P_PAF_PROVDIS_RSP 8 /* Provision Discovery Response */
83#define P2P_PAF_SUBTYPE_INVALID 255 /* Invalid Subtype */
84
85/* WiFi P2P Action Frame OUI Subtypes */
86#define P2P_AF_NOTICE_OF_ABSENCE 0 /* Notice of Absence */
87#define P2P_AF_PRESENCE_REQ 1 /* P2P Presence Request */
88#define P2P_AF_PRESENCE_RSP 2 /* P2P Presence Response */
89#define P2P_AF_GO_DISC_REQ 3 /* GO Discoverability Request */
90
91/* P2P Service Discovery related */
92#define P2PSD_ACTION_CATEGORY 0x04 /* Public action frame */
93#define P2PSD_ACTION_ID_GAS_IREQ 0x0a /* GAS Initial Request AF */
94#define P2PSD_ACTION_ID_GAS_IRESP 0x0b /* GAS Initial Response AF */
95#define P2PSD_ACTION_ID_GAS_CREQ 0x0c /* GAS Comback Request AF */
96#define P2PSD_ACTION_ID_GAS_CRESP 0x0d /* GAS Comback Response AF */
97
9f440b7b
AS
98/**
99 * struct brcmf_p2p_disc_st_le - set discovery state in firmware.
100 *
101 * @state: requested discovery state (see enum brcmf_p2p_disc_state).
102 * @chspec: channel parameter for %WL_P2P_DISC_ST_LISTEN state.
103 * @dwell: dwell time in ms for %WL_P2P_DISC_ST_LISTEN state.
104 */
105struct brcmf_p2p_disc_st_le {
106 u8 state;
107 __le16 chspec;
108 __le16 dwell;
109};
110
111/**
112 * enum brcmf_p2p_disc_state - P2P discovery state values
113 *
114 * @WL_P2P_DISC_ST_SCAN: P2P discovery with wildcard SSID and P2P IE.
115 * @WL_P2P_DISC_ST_LISTEN: P2P discovery off-channel for specified time.
116 * @WL_P2P_DISC_ST_SEARCH: P2P discovery with P2P wildcard SSID and P2P IE.
117 */
118enum brcmf_p2p_disc_state {
119 WL_P2P_DISC_ST_SCAN,
120 WL_P2P_DISC_ST_LISTEN,
121 WL_P2P_DISC_ST_SEARCH
122};
123
124/**
125 * struct brcmf_p2p_scan_le - P2P specific scan request.
126 *
127 * @type: type of scan method requested (values: 'E' or 'S').
128 * @reserved: reserved (ignored).
129 * @eparams: parameters used for type 'E'.
130 * @sparams: parameters used for type 'S'.
131 */
132struct brcmf_p2p_scan_le {
133 u8 type;
134 u8 reserved[3];
135 union {
136 struct brcmf_escan_params_le eparams;
137 struct brcmf_scan_params_le sparams;
138 };
139};
140
e6da3400
HM
141/**
142 * struct brcmf_p2p_pub_act_frame - WiFi P2P Public Action Frame
143 *
144 * @category: P2P_PUB_AF_CATEGORY
145 * @action: P2P_PUB_AF_ACTION
146 * @oui[3]: P2P_OUI
147 * @oui_type: OUI type - P2P_VER
148 * @subtype: OUI subtype - P2P_TYPE_*
149 * @dialog_token: nonzero, identifies req/rsp transaction
150 * @elts[1]: Variable length information elements.
151 */
152struct brcmf_p2p_pub_act_frame {
153 u8 category;
154 u8 action;
155 u8 oui[3];
156 u8 oui_type;
157 u8 subtype;
158 u8 dialog_token;
159 u8 elts[1];
160};
161
162/**
163 * struct brcmf_p2p_action_frame - WiFi P2P Action Frame
164 *
165 * @category: P2P_AF_CATEGORY
166 * @OUI[3]: OUI - P2P_OUI
167 * @type: OUI Type - P2P_VER
168 * @subtype: OUI Subtype - P2P_AF_*
169 * @dialog_token: nonzero, identifies req/resp tranaction
170 * @elts[1]: Variable length information elements.
171 */
172struct brcmf_p2p_action_frame {
173 u8 category;
174 u8 oui[3];
175 u8 type;
176 u8 subtype;
177 u8 dialog_token;
178 u8 elts[1];
179};
180
181/**
182 * struct brcmf_p2psd_gas_pub_act_frame - Wi-Fi GAS Public Action Frame
183 *
184 * @category: 0x04 Public Action Frame
185 * @action: 0x6c Advertisement Protocol
186 * @dialog_token: nonzero, identifies req/rsp transaction
187 * @query_data[1]: Query Data. SD gas ireq SD gas iresp
188 */
189struct brcmf_p2psd_gas_pub_act_frame {
190 u8 category;
191 u8 action;
192 u8 dialog_token;
193 u8 query_data[1];
194};
195
18e2f61d
HM
196/**
197 * struct brcmf_config_af_params - Action Frame Parameters for tx.
198 *
199 * @max_tx_retry: max tx retry count if tx no ack.
200 * @mpc_onoff: To make sure to send successfully action frame, we have to
201 * turn off mpc 0: off, 1: on, (-1): do nothing
202 */
203struct brcmf_config_af_params {
204 s32 max_tx_retry;
205 s32 mpc_onoff;
206};
e6da3400
HM
207
208/**
209 * brcmf_p2p_is_pub_action() - true if p2p public type frame.
210 *
211 * @frame: action frame data.
212 * @frame_len: length of action frame data.
213 *
214 * Determine if action frame is p2p public action type
215 */
216static bool brcmf_p2p_is_pub_action(void *frame, u32 frame_len)
217{
218 struct brcmf_p2p_pub_act_frame *pact_frm;
219
220 if (frame == NULL)
221 return false;
222
223 pact_frm = (struct brcmf_p2p_pub_act_frame *)frame;
224 if (frame_len < sizeof(struct brcmf_p2p_pub_act_frame) - 1)
225 return false;
226
227 if (pact_frm->category == P2P_PUB_AF_CATEGORY &&
228 pact_frm->action == P2P_PUB_AF_ACTION &&
229 pact_frm->oui_type == P2P_VER &&
230 memcmp(pact_frm->oui, P2P_OUI, P2P_OUI_LEN) == 0)
231 return true;
232
233 return false;
234}
235
236/**
237 * brcmf_p2p_is_p2p_action() - true if p2p action type frame.
238 *
239 * @frame: action frame data.
240 * @frame_len: length of action frame data.
241 *
242 * Determine if action frame is p2p action type
243 */
244static bool brcmf_p2p_is_p2p_action(void *frame, u32 frame_len)
245{
246 struct brcmf_p2p_action_frame *act_frm;
247
248 if (frame == NULL)
249 return false;
250
251 act_frm = (struct brcmf_p2p_action_frame *)frame;
252 if (frame_len < sizeof(struct brcmf_p2p_action_frame) - 1)
253 return false;
254
255 if (act_frm->category == P2P_AF_CATEGORY &&
256 act_frm->type == P2P_VER &&
257 memcmp(act_frm->oui, P2P_OUI, P2P_OUI_LEN) == 0)
258 return true;
259
260 return false;
261}
262
263/**
264 * brcmf_p2p_is_gas_action() - true if p2p gas action type frame.
265 *
266 * @frame: action frame data.
267 * @frame_len: length of action frame data.
268 *
269 * Determine if action frame is p2p gas action type
270 */
271static bool brcmf_p2p_is_gas_action(void *frame, u32 frame_len)
272{
273 struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm;
274
275 if (frame == NULL)
276 return false;
277
278 sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame;
279 if (frame_len < sizeof(struct brcmf_p2psd_gas_pub_act_frame) - 1)
280 return false;
281
282 if (sd_act_frm->category != P2PSD_ACTION_CATEGORY)
283 return false;
284
285 if (sd_act_frm->action == P2PSD_ACTION_ID_GAS_IREQ ||
286 sd_act_frm->action == P2PSD_ACTION_ID_GAS_IRESP ||
287 sd_act_frm->action == P2PSD_ACTION_ID_GAS_CREQ ||
288 sd_act_frm->action == P2PSD_ACTION_ID_GAS_CRESP)
289 return true;
290
291 return false;
292}
293
294/**
295 * brcmf_p2p_print_actframe() - debug print routine.
296 *
297 * @tx: Received or to be transmitted
298 * @frame: action frame data.
299 * @frame_len: length of action frame data.
300 *
301 * Print information about the p2p action frame
302 */
303static void brcmf_p2p_print_actframe(bool tx, void *frame, u32 frame_len)
304{
305 struct brcmf_p2p_pub_act_frame *pact_frm;
306 struct brcmf_p2p_action_frame *act_frm;
307 struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm;
308
309 if (!frame || frame_len <= 2)
310 return;
311
312 if (brcmf_p2p_is_pub_action(frame, frame_len)) {
313 pact_frm = (struct brcmf_p2p_pub_act_frame *)frame;
314 switch (pact_frm->subtype) {
315 case P2P_PAF_GON_REQ:
316 brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Req Frame\n",
317 (tx) ? "TX" : "RX");
318 break;
319 case P2P_PAF_GON_RSP:
320 brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Rsp Frame\n",
321 (tx) ? "TX" : "RX");
322 break;
323 case P2P_PAF_GON_CONF:
324 brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Confirm Frame\n",
325 (tx) ? "TX" : "RX");
326 break;
327 case P2P_PAF_INVITE_REQ:
328 brcmf_dbg(TRACE, "%s P2P Invitation Request Frame\n",
329 (tx) ? "TX" : "RX");
330 break;
331 case P2P_PAF_INVITE_RSP:
332 brcmf_dbg(TRACE, "%s P2P Invitation Response Frame\n",
333 (tx) ? "TX" : "RX");
334 break;
335 case P2P_PAF_DEVDIS_REQ:
336 brcmf_dbg(TRACE, "%s P2P Device Discoverability Request Frame\n",
337 (tx) ? "TX" : "RX");
338 break;
339 case P2P_PAF_DEVDIS_RSP:
340 brcmf_dbg(TRACE, "%s P2P Device Discoverability Response Frame\n",
341 (tx) ? "TX" : "RX");
342 break;
343 case P2P_PAF_PROVDIS_REQ:
344 brcmf_dbg(TRACE, "%s P2P Provision Discovery Request Frame\n",
345 (tx) ? "TX" : "RX");
346 break;
347 case P2P_PAF_PROVDIS_RSP:
348 brcmf_dbg(TRACE, "%s P2P Provision Discovery Response Frame\n",
349 (tx) ? "TX" : "RX");
350 break;
351 default:
352 brcmf_dbg(TRACE, "%s Unknown P2P Public Action Frame\n",
353 (tx) ? "TX" : "RX");
354 break;
355 }
356 } else if (brcmf_p2p_is_p2p_action(frame, frame_len)) {
357 act_frm = (struct brcmf_p2p_action_frame *)frame;
358 switch (act_frm->subtype) {
359 case P2P_AF_NOTICE_OF_ABSENCE:
360 brcmf_dbg(TRACE, "%s P2P Notice of Absence Frame\n",
361 (tx) ? "TX" : "RX");
362 break;
363 case P2P_AF_PRESENCE_REQ:
364 brcmf_dbg(TRACE, "%s P2P Presence Request Frame\n",
365 (tx) ? "TX" : "RX");
366 break;
367 case P2P_AF_PRESENCE_RSP:
368 brcmf_dbg(TRACE, "%s P2P Presence Response Frame\n",
369 (tx) ? "TX" : "RX");
370 break;
371 case P2P_AF_GO_DISC_REQ:
372 brcmf_dbg(TRACE, "%s P2P Discoverability Request Frame\n",
373 (tx) ? "TX" : "RX");
374 break;
375 default:
376 brcmf_dbg(TRACE, "%s Unknown P2P Action Frame\n",
377 (tx) ? "TX" : "RX");
378 }
379
380 } else if (brcmf_p2p_is_gas_action(frame, frame_len)) {
381 sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame;
382 switch (sd_act_frm->action) {
383 case P2PSD_ACTION_ID_GAS_IREQ:
384 brcmf_dbg(TRACE, "%s P2P GAS Initial Request\n",
385 (tx) ? "TX" : "RX");
386 break;
387 case P2PSD_ACTION_ID_GAS_IRESP:
388 brcmf_dbg(TRACE, "%s P2P GAS Initial Response\n",
389 (tx) ? "TX" : "RX");
390 break;
391 case P2PSD_ACTION_ID_GAS_CREQ:
392 brcmf_dbg(TRACE, "%s P2P GAS Comback Request\n",
393 (tx) ? "TX" : "RX");
394 break;
395 case P2PSD_ACTION_ID_GAS_CRESP:
396 brcmf_dbg(TRACE, "%s P2P GAS Comback Response\n",
397 (tx) ? "TX" : "RX");
398 break;
399 default:
400 brcmf_dbg(TRACE, "%s Unknown P2P GAS Frame\n",
401 (tx) ? "TX" : "RX");
402 break;
403 }
404 }
405}
406
9f440b7b
AS
407/**
408 * brcmf_p2p_set_firmware() - prepare firmware for peer-to-peer operation.
409 *
2fde59d9
HM
410 * @ifp: ifp to use for iovars (primary).
411 * @p2p_mac: mac address to configure for p2p_da_override
9f440b7b 412 */
2fde59d9 413static int brcmf_p2p_set_firmware(struct brcmf_if *ifp, u8 *p2p_mac)
9f440b7b 414{
9f440b7b
AS
415 s32 ret = 0;
416
2fde59d9 417 brcmf_fil_iovar_int_set(ifp, "apsta", 1);
9f440b7b
AS
418
419 /* In case of COB type, firmware has default mac address
420 * After Initializing firmware, we have to set current mac address to
421 * firmware for P2P device address
422 */
2fde59d9
HM
423 ret = brcmf_fil_iovar_data_set(ifp, "p2p_da_override", p2p_mac,
424 ETH_ALEN);
9f440b7b
AS
425 if (ret)
426 brcmf_err("failed to update device address ret %d\n", ret);
427
428 return ret;
429}
430
431/**
432 * brcmf_p2p_generate_bss_mac() - derive mac addresses for P2P.
433 *
434 * @p2p: P2P specific data.
435 *
436 * P2P needs mac addresses for P2P device and interface. These are
437 * derived from the primary net device, ie. the permanent ethernet
438 * address of the device.
439 */
440static void brcmf_p2p_generate_bss_mac(struct brcmf_p2p_info *p2p)
441{
2fde59d9
HM
442 struct brcmf_if *pri_ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
443 struct brcmf_if *p2p_ifp = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif->ifp;
444
9f440b7b
AS
445 /* Generate the P2P Device Address. This consists of the device's
446 * primary MAC address with the locally administered bit set.
447 */
2fde59d9 448 memcpy(p2p->dev_addr, pri_ifp->mac_addr, ETH_ALEN);
9f440b7b 449 p2p->dev_addr[0] |= 0x02;
2fde59d9 450 memcpy(p2p_ifp->mac_addr, p2p->dev_addr, ETH_ALEN);
9f440b7b
AS
451
452 /* Generate the P2P Interface Address. If the discovery and connection
453 * BSSCFGs need to simultaneously co-exist, then this address must be
454 * different from the P2P Device Address, but also locally administered.
455 */
456 memcpy(p2p->int_addr, p2p->dev_addr, ETH_ALEN);
457 p2p->int_addr[4] ^= 0x80;
458}
459
460/**
461 * brcmf_p2p_scan_is_p2p_request() - is cfg80211 scan request a P2P scan.
462 *
463 * @request: the scan request as received from cfg80211.
464 *
465 * returns true if one of the ssids in the request matches the
466 * P2P wildcard ssid; otherwise returns false.
467 */
468static bool brcmf_p2p_scan_is_p2p_request(struct cfg80211_scan_request *request)
469{
470 struct cfg80211_ssid *ssids = request->ssids;
471 int i;
472
473 for (i = 0; i < request->n_ssids; i++) {
474 if (ssids[i].ssid_len != BRCMF_P2P_WILDCARD_SSID_LEN)
475 continue;
476
477 brcmf_dbg(INFO, "comparing ssid \"%s\"", ssids[i].ssid);
478 if (!memcmp(BRCMF_P2P_WILDCARD_SSID, ssids[i].ssid,
479 BRCMF_P2P_WILDCARD_SSID_LEN))
480 return true;
481 }
482 return false;
483}
484
485/**
486 * brcmf_p2p_set_discover_state - set discover state in firmware.
487 *
488 * @ifp: low-level interface object.
489 * @state: discover state to set.
490 * @chanspec: channel parameters (for state @WL_P2P_DISC_ST_LISTEN only).
491 * @listen_ms: duration to listen (for state @WL_P2P_DISC_ST_LISTEN only).
492 */
493static s32 brcmf_p2p_set_discover_state(struct brcmf_if *ifp, u8 state,
494 u16 chanspec, u16 listen_ms)
495{
496 struct brcmf_p2p_disc_st_le discover_state;
497 s32 ret = 0;
498 brcmf_dbg(TRACE, "enter\n");
499
500 discover_state.state = state;
501 discover_state.chspec = cpu_to_le16(chanspec);
502 discover_state.dwell = cpu_to_le16(listen_ms);
503 ret = brcmf_fil_bsscfg_data_set(ifp, "p2p_state", &discover_state,
504 sizeof(discover_state));
505 return ret;
506}
507
9f440b7b
AS
508/**
509 * brcmf_p2p_deinit_discovery() - disable P2P device discovery.
510 *
511 * @p2p: P2P specific data.
512 *
2fde59d9 513 * Resets the discovery state and disables it in firmware.
9f440b7b
AS
514 */
515static s32 brcmf_p2p_deinit_discovery(struct brcmf_p2p_info *p2p)
516{
2fde59d9 517 struct brcmf_cfg80211_vif *vif;
9f440b7b 518
2fde59d9 519 brcmf_dbg(TRACE, "enter\n");
9f440b7b
AS
520
521 /* Set the discovery state to SCAN */
2fde59d9
HM
522 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
523 (void)brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
9f440b7b
AS
524
525 /* Disable P2P discovery in the firmware */
2fde59d9
HM
526 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
527 (void)brcmf_fil_iovar_int_set(vif->ifp, "p2p_disc", 0);
9f440b7b
AS
528
529 return 0;
530}
531
532/**
533 * brcmf_p2p_enable_discovery() - initialize and configure discovery.
534 *
535 * @p2p: P2P specific data.
9f440b7b
AS
536 *
537 * Initializes the discovery device and configure the virtual interface.
538 */
0de8aace 539static int brcmf_p2p_enable_discovery(struct brcmf_p2p_info *p2p)
9f440b7b
AS
540{
541 struct brcmf_cfg80211_vif *vif;
542 s32 ret = 0;
543
544 brcmf_dbg(TRACE, "enter\n");
545 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
2fde59d9
HM
546 if (!vif) {
547 brcmf_err("P2P config device not available\n");
548 ret = -EPERM;
0de8aace 549 goto exit;
9f440b7b
AS
550 }
551
2fde59d9
HM
552 if (test_bit(BRCMF_P2P_STATUS_ENABLED, &p2p->status)) {
553 brcmf_dbg(INFO, "P2P config device already configured\n");
9f440b7b
AS
554 goto exit;
555 }
556
2fde59d9
HM
557 /* Re-initialize P2P Discovery in the firmware */
558 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
559 ret = brcmf_fil_iovar_int_set(vif->ifp, "p2p_disc", 1);
560 if (ret < 0) {
561 brcmf_err("set p2p_disc error\n");
562 goto exit;
563 }
9f440b7b 564 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
2fde59d9
HM
565 ret = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
566 if (ret < 0) {
567 brcmf_err("unable to set WL_P2P_DISC_ST_SCAN\n");
568 goto exit;
569 }
9f440b7b
AS
570
571 /*
572 * Set wsec to any non-zero value in the discovery bsscfg
573 * to ensure our P2P probe responses have the privacy bit
574 * set in the 802.11 WPA IE. Some peer devices may not
575 * initiate WPS with us if this bit is not set.
576 */
577 ret = brcmf_fil_bsscfg_int_set(vif->ifp, "wsec", AES_ENABLED);
2fde59d9 578 if (ret < 0) {
9f440b7b 579 brcmf_err("wsec error %d\n", ret);
2fde59d9
HM
580 goto exit;
581 }
9f440b7b 582
2fde59d9 583 set_bit(BRCMF_P2P_STATUS_ENABLED, &p2p->status);
9f440b7b
AS
584exit:
585 return ret;
586}
587
0de8aace 588/**
9f440b7b
AS
589 * brcmf_p2p_escan() - initiate a P2P scan.
590 *
591 * @p2p: P2P specific data.
592 * @num_chans: number of channels to scan.
593 * @chanspecs: channel parameters for @num_chans channels.
594 * @search_state: P2P discover state to use.
595 * @action: scan action to pass to firmware.
596 * @bss_type: type of P2P bss.
597 */
598static s32 brcmf_p2p_escan(struct brcmf_p2p_info *p2p, u32 num_chans,
599 u16 chanspecs[], s32 search_state, u16 action,
600 enum p2p_bss_type bss_type)
601{
602 s32 ret = 0;
603 s32 memsize = offsetof(struct brcmf_p2p_scan_le,
604 eparams.params_le.channel_list);
605 s32 nprobes;
606 s32 active;
607 u32 i;
608 u8 *memblk;
609 struct brcmf_cfg80211_vif *vif;
610 struct brcmf_p2p_scan_le *p2p_params;
611 struct brcmf_scan_params_le *sparams;
612 struct brcmf_ssid ssid;
613
9f440b7b
AS
614 memsize += num_chans * sizeof(__le16);
615 memblk = kzalloc(memsize, GFP_KERNEL);
616 if (!memblk)
617 return -ENOMEM;
618
619 vif = p2p->bss_idx[bss_type].vif;
620 if (vif == NULL) {
621 brcmf_err("no vif for bss type %d\n", bss_type);
622 ret = -EINVAL;
623 goto exit;
624 }
625
626 switch (search_state) {
627 case WL_P2P_DISC_ST_SEARCH:
628 /*
629 * If we in SEARCH STATE, we don't need to set SSID explictly
630 * because dongle use P2P WILDCARD internally by default
631 */
632 /* use null ssid */
633 ssid.SSID_len = 0;
634 memset(ssid.SSID, 0, sizeof(ssid.SSID));
635 break;
636 case WL_P2P_DISC_ST_SCAN:
637 /*
638 * wpa_supplicant has p2p_find command with type social or
639 * progressive. For progressive, we need to set the ssid to
640 * P2P WILDCARD because we just do broadcast scan unless
641 * setting SSID.
642 */
643 ssid.SSID_len = BRCMF_P2P_WILDCARD_SSID_LEN;
644 memcpy(ssid.SSID, BRCMF_P2P_WILDCARD_SSID, ssid.SSID_len);
645 break;
646 default:
647 brcmf_err(" invalid search state %d\n", search_state);
648 ret = -EINVAL;
649 goto exit;
650 }
651
652 brcmf_p2p_set_discover_state(vif->ifp, search_state, 0, 0);
653
654 /*
655 * set p2p scan parameters.
656 */
657 p2p_params = (struct brcmf_p2p_scan_le *)memblk;
658 p2p_params->type = 'E';
659
660 /* determine the scan engine parameters */
661 sparams = &p2p_params->eparams.params_le;
662 sparams->bss_type = DOT11_BSSTYPE_ANY;
663 if (p2p->cfg->active_scan)
664 sparams->scan_type = 0;
665 else
666 sparams->scan_type = 1;
667
668 memset(&sparams->bssid, 0xFF, ETH_ALEN);
669 if (ssid.SSID_len)
670 memcpy(sparams->ssid_le.SSID, ssid.SSID, ssid.SSID_len);
671 sparams->ssid_le.SSID_len = cpu_to_le32(ssid.SSID_len);
672 sparams->home_time = cpu_to_le32(P2PAPI_SCAN_HOME_TIME_MS);
673
674 /*
675 * SOCIAL_CHAN_CNT + 1 takes care of the Progressive scan
676 * supported by the supplicant.
677 */
678 if (num_chans == SOCIAL_CHAN_CNT || num_chans == (SOCIAL_CHAN_CNT + 1))
679 active = P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS;
680 else if (num_chans == AF_PEER_SEARCH_CNT)
681 active = P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS;
682 else if (wl_get_vif_state_all(p2p->cfg, BRCMF_VIF_STATUS_CONNECTED))
683 active = -1;
684 else
685 active = P2PAPI_SCAN_DWELL_TIME_MS;
686
687 /* Override scan params to find a peer for a connection */
688 if (num_chans == 1) {
689 active = WL_SCAN_CONNECT_DWELL_TIME_MS;
18e2f61d 690 /* WAR to sync with presence period of VSDB GO.
9f440b7b
AS
691 * send probe request more frequently
692 */
693 nprobes = active / WL_SCAN_JOIN_PROBE_INTERVAL_MS;
694 } else {
695 nprobes = active / P2PAPI_SCAN_NPROBS_TIME_MS;
696 }
697
698 if (nprobes <= 0)
699 nprobes = 1;
700
701 brcmf_dbg(INFO, "nprobes # %d, active_time %d\n", nprobes, active);
702 sparams->active_time = cpu_to_le32(active);
703 sparams->nprobes = cpu_to_le32(nprobes);
704 sparams->passive_time = cpu_to_le32(-1);
705 sparams->channel_num = cpu_to_le32(num_chans &
706 BRCMF_SCAN_PARAMS_COUNT_MASK);
707 for (i = 0; i < num_chans; i++)
708 sparams->channel_list[i] = cpu_to_le16(chanspecs[i]);
709
710 /* set the escan specific parameters */
711 p2p_params->eparams.version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION);
712 p2p_params->eparams.action = cpu_to_le16(action);
713 p2p_params->eparams.sync_id = cpu_to_le16(0x1234);
714 /* perform p2p scan on primary device */
715 ret = brcmf_fil_bsscfg_data_set(vif->ifp, "p2p_scan", memblk, memsize);
716 if (!ret)
717 set_bit(BRCMF_SCAN_STATUS_BUSY, &p2p->cfg->scan_status);
718exit:
719 kfree(memblk);
720 return ret;
721}
722
723/**
724 * brcmf_p2p_run_escan() - escan callback for peer-to-peer.
725 *
726 * @cfg: driver private data for cfg80211 interface.
727 * @ndev: net device for which scan is requested.
728 * @request: scan request from cfg80211.
729 * @action: scan action.
730 *
731 * Determines the P2P discovery state based to scan request parameters and
732 * validates the channels in the request.
733 */
734static s32 brcmf_p2p_run_escan(struct brcmf_cfg80211_info *cfg,
735 struct net_device *ndev,
736 struct cfg80211_scan_request *request,
737 u16 action)
738{
739 struct brcmf_p2p_info *p2p = &cfg->p2p;
740 s32 err = 0;
741 s32 search_state = WL_P2P_DISC_ST_SCAN;
742 struct brcmf_cfg80211_vif *vif;
743 struct net_device *dev = NULL;
744 int i, num_nodfs = 0;
745 u16 *chanspecs;
746
747 brcmf_dbg(TRACE, "enter\n");
748
749 if (!request) {
750 err = -EINVAL;
751 goto exit;
752 }
753
754 if (request->n_channels) {
755 chanspecs = kcalloc(request->n_channels, sizeof(*chanspecs),
756 GFP_KERNEL);
757 if (!chanspecs) {
758 err = -ENOMEM;
759 goto exit;
760 }
761 vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
762 if (vif)
763 dev = vif->wdev.netdev;
764 if (request->n_channels == 3 &&
765 request->channels[0]->hw_value == SOCIAL_CHAN_1 &&
766 request->channels[1]->hw_value == SOCIAL_CHAN_2 &&
767 request->channels[2]->hw_value == SOCIAL_CHAN_3) {
768 /* SOCIAL CHANNELS 1, 6, 11 */
769 search_state = WL_P2P_DISC_ST_SEARCH;
770 brcmf_dbg(INFO, "P2P SEARCH PHASE START\n");
771 } else if (dev != NULL && vif->mode == WL_MODE_AP) {
772 /* If you are already a GO, then do SEARCH only */
773 brcmf_dbg(INFO, "Already a GO. Do SEARCH Only\n");
774 search_state = WL_P2P_DISC_ST_SEARCH;
775 } else {
776 brcmf_dbg(INFO, "P2P SCAN STATE START\n");
777 }
778
779 /*
780 * no P2P scanning on passive or DFS channels.
781 */
782 for (i = 0; i < request->n_channels; i++) {
783 struct ieee80211_channel *chan = request->channels[i];
784
785 if (chan->flags & (IEEE80211_CHAN_RADAR |
786 IEEE80211_CHAN_PASSIVE_SCAN))
787 continue;
788
789 chanspecs[i] = channel_to_chanspec(chan);
790 brcmf_dbg(INFO, "%d: chan=%d, channel spec=%x\n",
791 num_nodfs, chan->hw_value, chanspecs[i]);
792 num_nodfs++;
793 }
794 err = brcmf_p2p_escan(p2p, num_nodfs, chanspecs, search_state,
795 action, P2PAPI_BSSCFG_DEVICE);
796 }
797exit:
798 if (err)
799 brcmf_err("error (%d)\n", err);
800 return err;
801}
802
803/**
804 * brcmf_p2p_scan_prep() - prepare scan based on request.
805 *
806 * @wiphy: wiphy device.
807 * @request: scan request from cfg80211.
0f8ffe17 808 * @vif: vif on which scan request is to be executed.
9f440b7b
AS
809 *
810 * Prepare the scan appropriately for type of scan requested. Overrides the
811 * escan .run() callback for peer-to-peer scanning.
812 */
813int brcmf_p2p_scan_prep(struct wiphy *wiphy,
0f8ffe17
HM
814 struct cfg80211_scan_request *request,
815 struct brcmf_cfg80211_vif *vif)
9f440b7b
AS
816{
817 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
818 struct brcmf_p2p_info *p2p = &cfg->p2p;
819 int err = 0;
820
821 if (brcmf_p2p_scan_is_p2p_request(request)) {
822 /* find my listen channel */
823 err = cfg80211_get_p2p_attr(request->ie, request->ie_len,
824 IEEE80211_P2P_ATTR_LISTEN_CHANNEL,
825 &p2p->listen_channel, 1);
826 if (err < 0)
827 return err;
828
829 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
830 brcmf_dbg(INFO, "P2P: GO_NEG_PHASE status cleared\n");
831
0de8aace 832 err = brcmf_p2p_enable_discovery(p2p);
0f8ffe17
HM
833 if (err)
834 return err;
9f440b7b 835
0f8ffe17 836 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
9f440b7b 837
0f8ffe17
HM
838 /* override .run_escan() callback. */
839 cfg->escan_info.run = brcmf_p2p_run_escan;
9f440b7b 840 }
0f8ffe17
HM
841 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBREQ_FLAG,
842 request->ie, request->ie_len);
9f440b7b
AS
843 return err;
844}
845
0de8aace 846
f2058dde
HM
847/**
848 * brcmf_p2p_discover_listen() - set firmware to discover listen state.
849 *
850 * @p2p: p2p device.
851 * @freq: center frequency for discover listen.
852 * #@duration: time in ms to stay on channel.
853 *
854 */
855static s32
856brcmf_p2p_discover_listen(struct brcmf_p2p_info *p2p,
857 struct ieee80211_channel *channel, u32 duration)
858{
859 struct brcmf_cfg80211_vif *vif;
860 s32 err = 0;
861 u16 chanspec;
862
863 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
864 if (!vif) {
865 brcmf_err("Discovery is not set, so we have nothing to do\n");
866 err = -EPERM;
867 goto exit;
868 }
869
870 if (test_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status)) {
871 brcmf_err("Previous LISTEN is not completed yet\n");
872 /* WAR: prevent cookie mismatch in wpa_supplicant return OK */
873 goto exit;
874 }
875
876 chanspec = channel_to_chanspec(channel);
877 err = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_LISTEN,
878 chanspec, (u16)duration);
879 if (!err) {
880 set_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status);
881 p2p->remain_on_channel_cookie++;
882 }
883exit:
884 return err;
885}
886
887
0de8aace
HM
888/**
889 * brcmf_p2p_remain_on_channel() - put device on channel and stay there.
890 *
891 * @wiphy: wiphy device.
892 * @channel: channel to stay on.
893 * @duration: time in ms to remain on channel.
894 *
895 */
896int brcmf_p2p_remain_on_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
897 struct ieee80211_channel *channel,
898 unsigned int duration, u64 *cookie)
899{
900 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
901 struct brcmf_p2p_info *p2p = &cfg->p2p;
0de8aace 902 s32 err;
0de8aace
HM
903
904 brcmf_dbg(TRACE, "Enter, channel: %d, duration ms (%d)\n",
905 ieee80211_frequency_to_channel(channel->center_freq),
906 duration);
907
0de8aace
HM
908 err = brcmf_p2p_enable_discovery(p2p);
909 if (err)
910 goto exit;
f2058dde 911 err = brcmf_p2p_discover_listen(p2p, channel, duration);
0de8aace
HM
912 if (err)
913 goto exit;
914
f2058dde
HM
915 memcpy(&p2p->remain_on_channel, channel, sizeof(*channel));
916 *cookie = p2p->remain_on_channel_cookie;
1ce3086c 917 cfg80211_ready_on_channel(wdev, *cookie, channel, duration, GFP_KERNEL);
0de8aace
HM
918
919exit:
0de8aace
HM
920 return err;
921}
922
923
924/**
925 * brcmf_p2p_notify_listen_complete() - p2p listen has completed.
926 *
927 * @ifp: interfac control.
928 * @e: event message. Not used, to make it usable for fweh event dispatcher.
929 * @data: payload of message. Not used.
930 *
931 */
932int brcmf_p2p_notify_listen_complete(struct brcmf_if *ifp,
933 const struct brcmf_event_msg *e,
934 void *data)
935{
936 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
937 struct brcmf_p2p_info *p2p = &cfg->p2p;
938
939 brcmf_dbg(TRACE, "Enter\n");
f2058dde 940 if (test_and_clear_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN,
0de8aace 941 &p2p->status))
f2058dde
HM
942 cfg80211_remain_on_channel_expired(&ifp->vif->wdev,
943 p2p->remain_on_channel_cookie,
0de8aace
HM
944 &p2p->remain_on_channel,
945 GFP_KERNEL);
946 return 0;
947}
948
949
950/**
951 * brcmf_p2p_cancel_remain_on_channel() - cancel p2p listen state.
952 *
953 * @ifp: interfac control.
954 *
955 */
956void brcmf_p2p_cancel_remain_on_channel(struct brcmf_if *ifp)
957{
958 if (!ifp)
959 return;
960 brcmf_p2p_set_discover_state(ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
961 brcmf_p2p_notify_listen_complete(ifp, NULL, NULL);
962}
963
964
e6da3400
HM
965/**
966 * brcmf_p2p_notify_action_frame_rx() - received action frame.
967 *
968 * @ifp: interfac control.
969 * @e: event message. Not used, to make it usable for fweh event dispatcher.
970 * @data: payload of message, containing action frame data.
971 *
972 */
973int brcmf_p2p_notify_action_frame_rx(struct brcmf_if *ifp,
974 const struct brcmf_event_msg *e,
975 void *data)
976{
977 struct wireless_dev *wdev;
978 u32 mgmt_frame_len = e->datalen - sizeof(struct brcmf_rx_mgmt_data);
979 struct brcmf_rx_mgmt_data *rxframe = (struct brcmf_rx_mgmt_data *)data;
980 u16 chanspec = be16_to_cpu(rxframe->chanspec);
981 struct ieee80211_mgmt *mgmt_frame;
982 s32 err;
983 s32 freq;
984 u16 mgmt_type;
985
986 /* Check if wpa_supplicant has registered for this frame */
987 brcmf_dbg(INFO, "ifp->vif->mgmt_rx_reg %04x\n", ifp->vif->mgmt_rx_reg);
988 mgmt_type = (IEEE80211_STYPE_ACTION & IEEE80211_FCTL_STYPE) >> 4;
989 if ((ifp->vif->mgmt_rx_reg & BIT(mgmt_type)) == 0)
990 return 0;
991
992 brcmf_p2p_print_actframe(false, (u8 *)(rxframe + 1), mgmt_frame_len);
993
994 mgmt_frame = kzalloc(offsetof(struct ieee80211_mgmt, u) +
995 mgmt_frame_len, GFP_KERNEL);
996 if (!mgmt_frame) {
997 brcmf_err("No memory available for action frame\n");
998 return -ENOMEM;
999 }
1000 memcpy(mgmt_frame->da, ifp->mac_addr, ETH_ALEN);
1001 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSSID, mgmt_frame->bssid,
1002 ETH_ALEN);
1003 if (err < 0)
1004 brcmf_err("BRCMF_C_GET_BSSID error %d\n", err);
1005 memcpy(mgmt_frame->sa, e->addr, ETH_ALEN);
1006 mgmt_frame->frame_control = cpu_to_le16(IEEE80211_STYPE_ACTION);
1007 memcpy(&mgmt_frame->u, (u8 *)(rxframe + 1), mgmt_frame_len);
1008 mgmt_frame_len += offsetof(struct ieee80211_mgmt, u);
1009
1010 freq = ieee80211_channel_to_frequency(CHSPEC_CHANNEL(chanspec),
1011 CHSPEC_IS2G(chanspec) ?
1012 IEEE80211_BAND_2GHZ :
1013 IEEE80211_BAND_5GHZ);
1014 wdev = ifp->ndev->ieee80211_ptr;
1015 cfg80211_rx_mgmt(wdev, freq, 0, (u8 *)mgmt_frame, mgmt_frame_len,
1016 GFP_ATOMIC);
1017
1018 kfree(mgmt_frame);
1019 return 0;
1020}
1021
1022
18e2f61d
HM
1023/**
1024 * brcmf_p2p_notify_action_tx_complete() - transmit action frame complete
1025 *
1026 * @ifp: interfac control.
1027 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1028 * @data: not used.
1029 *
1030 */
1031int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp,
1032 const struct brcmf_event_msg *e,
1033 void *data)
1034{
1035 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
1036 struct brcmf_p2p_info *p2p = &cfg->p2p;
1037
1038 brcmf_dbg(INFO, "Enter: status %d\n", e->status);
1039
1040 if (e->status == BRCMF_E_STATUS_SUCCESS)
1041 set_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
1042 else
1043 set_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
1044 /* for now complete the receiver process here !! */
1045 complete(&p2p->send_af_done);
1046
1047 return 0;
1048}
1049
1050
1051/**
1052 * brcmf_p2p_tx_action_frame() - send action frame over fil.
1053 *
1054 * @p2p: p2p info struct for vif.
1055 * @af_params: action frame data/info.
1056 *
1057 * Send an action frame immediately without doing channel synchronization.
1058 *
1059 * This function waits for a completion event before returning.
1060 * The WLC_E_ACTION_FRAME_COMPLETE event will be received when the action
1061 * frame is transmitted.
1062 */
1063static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p,
1064 struct brcmf_fil_af_params_le *af_params)
1065{
1066 struct brcmf_cfg80211_vif *vif;
1067 s32 err = 0;
1068 s32 timeout = 0;
1069
1070 brcmf_dbg(TRACE, "Enter\n");
1071
1072 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
1073 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
1074
1075 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
1076 err = brcmf_fil_bsscfg_data_set(vif->ifp, "actframe", af_params,
1077 sizeof(*af_params));
1078 if (err) {
1079 brcmf_err(" sending action frame has failed\n");
1080 goto exit;
1081 }
1082
1083 timeout = wait_for_completion_timeout(&p2p->send_af_done,
1084 msecs_to_jiffies(P2P_AF_MAX_WAIT_TIME));
1085
1086 if (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status)) {
1087 brcmf_dbg(TRACE, "TX action frame operation is success\n");
1088 } else {
1089 err = -EIO;
1090 brcmf_dbg(TRACE, "TX action frame operation has failed\n");
1091 }
1092 /* clear status bit for action tx */
1093 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
1094 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
1095
1096exit:
1097 return err;
1098}
1099
1100
1101/**
1102 * brcmf_p2p_pub_af_tx() - public action frame tx routine.
1103 *
1104 * @cfg: driver private data for cfg80211 interface.
1105 * @af_params: action frame data/info.
1106 * @config_af_params: configuration data for action frame.
1107 *
1108 * routine which transmits ation frame public type.
1109 */
1110static s32 brcmf_p2p_pub_af_tx(struct brcmf_cfg80211_info *cfg,
1111 struct brcmf_fil_af_params_le *af_params,
1112 struct brcmf_config_af_params *config_af_params)
1113{
1114 struct brcmf_p2p_info *p2p = &cfg->p2p;
1115 struct brcmf_fil_action_frame_le *action_frame;
1116 struct brcmf_p2p_pub_act_frame *act_frm;
1117 s32 err = 0;
1118
1119 action_frame = &af_params->action_frame;
1120 act_frm = (struct brcmf_p2p_pub_act_frame *)(action_frame->data);
1121
1122 switch (act_frm->subtype) {
1123 case P2P_PAF_GON_REQ:
1124 brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status set\n");
1125 set_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
1126 config_af_params->mpc_onoff = 0;
1127 p2p->next_af_subtype = act_frm->subtype + 1;
1128 /* increase dwell time to wait for RESP frame */
1129 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1130 break;
1131 case P2P_PAF_GON_RSP:
1132 p2p->next_af_subtype = act_frm->subtype + 1;
1133 /* increase dwell time to wait for CONF frame */
1134 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1135 break;
1136 case P2P_PAF_GON_CONF:
1137 /* If we reached till GO Neg confirmation reset the filter */
1138 brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status cleared\n");
1139 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
1140 /* turn on mpc again if go nego is done */
1141 config_af_params->mpc_onoff = 1;
1142 /* minimize dwell time */
1143 af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1144 break;
1145 case P2P_PAF_INVITE_REQ:
1146 p2p->next_af_subtype = act_frm->subtype + 1;
1147 /* increase dwell time */
1148 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1149 break;
1150 case P2P_PAF_INVITE_RSP:
1151 /* minimize dwell time */
1152 af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1153 break;
1154 case P2P_PAF_DEVDIS_REQ:
1155 p2p->next_af_subtype = act_frm->subtype + 1;
1156 /* maximize dwell time to wait for RESP frame */
1157 af_params->dwell_time = cpu_to_le32(P2P_AF_LONG_DWELL_TIME);
1158 break;
1159 case P2P_PAF_DEVDIS_RSP:
1160 /* minimize dwell time */
1161 af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1162 break;
1163 case P2P_PAF_PROVDIS_REQ:
1164 config_af_params->mpc_onoff = 0;
1165 p2p->next_af_subtype = act_frm->subtype + 1;
1166 /* increase dwell time to wait for RESP frame */
1167 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1168 break;
1169 case P2P_PAF_PROVDIS_RSP:
1170 /* wpa_supplicant send go nego req right after prov disc */
1171 p2p->next_af_subtype = P2P_PAF_GON_REQ;
1172 /* increase dwell time to MED level */
1173 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1174 break;
1175 default:
1176 brcmf_err("Unknown p2p pub act frame subtype: %d\n",
1177 act_frm->subtype);
1178 err = -EINVAL;
1179 }
1180 return err;
1181}
1182
1183/**
1184 * brcmf_p2p_send_action_frame() - send action frame .
1185 *
1186 * @cfg: driver private data for cfg80211 interface.
1187 * @ndev: net device to transmit on.
1188 * @af_params: configuration data for action frame.
1189 */
1190bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info *cfg,
1191 struct net_device *ndev,
1192 struct brcmf_fil_af_params_le *af_params)
1193{
1194 struct brcmf_p2p_info *p2p = &cfg->p2p;
1195 struct brcmf_fil_action_frame_le *action_frame;
1196 struct brcmf_config_af_params config_af_params;
1197 u16 action_frame_len;
1198 bool ack = false;
1199 u8 category;
1200 u8 action;
1201 s32 tx_retry;
1202
1203 action_frame = &af_params->action_frame;
1204 action_frame_len = le16_to_cpu(action_frame->len);
1205
1206 brcmf_p2p_print_actframe(true, action_frame->data, action_frame_len);
1207
1208 /* Add the default dwell time. Dwell time to stay off-channel */
1209 /* to wait for a response action frame after transmitting an */
1210 /* GO Negotiation action frame */
1211 af_params->dwell_time = cpu_to_le32(P2P_AF_DWELL_TIME);
1212
1213 category = action_frame->data[DOT11_ACTION_CAT_OFF];
1214 action = action_frame->data[DOT11_ACTION_ACT_OFF];
1215
1216 /* initialize variables */
1217 p2p->next_af_subtype = P2P_PAF_SUBTYPE_INVALID;
1218
1219 /* config parameters */
1220 config_af_params.max_tx_retry = P2P_AF_TX_MAX_RETRY;
1221 config_af_params.mpc_onoff = -1;
1222
1223 if (brcmf_p2p_is_pub_action(action_frame->data, action_frame_len)) {
1224 /* p2p public action frame process */
1225 if (brcmf_p2p_pub_af_tx(cfg, af_params, &config_af_params)) {
1226 /* Just send unknown subtype frame with */
1227 /* default parameters. */
1228 brcmf_err("P2P Public action frame, unknown subtype.\n");
1229 }
1230 } else if (brcmf_p2p_is_gas_action(action_frame->data,
1231 action_frame_len)) {
1232 /* service discovery process */
1233 if (action == P2PSD_ACTION_ID_GAS_IREQ ||
1234 action == P2PSD_ACTION_ID_GAS_CREQ) {
1235 /* save next af suptype to cancel */
1236 /* remaining dwell time */
1237 p2p->next_af_subtype = action + 1;
1238
1239 af_params->dwell_time =
1240 cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1241 } else if (action == P2PSD_ACTION_ID_GAS_IRESP ||
1242 action == P2PSD_ACTION_ID_GAS_CRESP) {
1243 /* configure service discovery response frame */
1244 af_params->dwell_time =
1245 cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1246 } else {
1247 brcmf_err("Unknown action type: %d\n", action);
1248 goto exit;
1249 }
1250 } else if (brcmf_p2p_is_p2p_action(action_frame->data,
1251 action_frame_len)) {
1252 /* do not configure anything. it will be */
1253 /* sent with a default configuration */
1254 } else {
1255 brcmf_err("Unknown Frame: category 0x%x, action 0x%x\n",
1256 category, action);
1257 return false;
1258 }
1259
1260 /* if scan is ongoing, abort current scan. */
1261 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
1262 brcmf_abort_scanning(cfg);
1263
1264 /* To make sure to send successfully action frame, turn off mpc */
1265 if (config_af_params.mpc_onoff == 0)
1266 brcmf_set_mpc(ndev, 0);
1267
1268 /* if failed, retry it. tx_retry_max value is configure by .... */
1269 tx_retry = 0;
1270 while ((ack == false) && (tx_retry < config_af_params.max_tx_retry)) {
1271 ack = !brcmf_p2p_tx_action_frame(p2p, af_params);
1272 tx_retry++;
1273 }
1274 if (ack == false)
1275 brcmf_err("Failed to send Action Frame(retry %d)\n", tx_retry);
1276
1277exit:
1278 /* if all done, turn mpc on again */
1279 if (config_af_params.mpc_onoff == 1)
1280 brcmf_set_mpc(ndev, 1);
1281
1282 return ack;
1283}
1284
1285
9f440b7b
AS
1286/**
1287 * brcmf_p2p_attach() - attach for P2P.
1288 *
1289 * @cfg: driver private data for cfg80211 interface.
1290 */
2fde59d9 1291s32 brcmf_p2p_attach(struct brcmf_cfg80211_info *cfg)
9f440b7b 1292{
2fde59d9
HM
1293 struct brcmf_if *pri_ifp;
1294 struct brcmf_if *p2p_ifp;
1295 struct brcmf_cfg80211_vif *p2p_vif;
9f440b7b 1296 struct brcmf_p2p_info *p2p;
2fde59d9
HM
1297 struct brcmf_pub *drvr;
1298 s32 bssidx;
1299 s32 err = 0;
9f440b7b
AS
1300
1301 p2p = &cfg->p2p;
9f440b7b 1302 p2p->cfg = cfg;
2fde59d9
HM
1303
1304 drvr = cfg->pub;
1305
1306 pri_ifp = drvr->iflist[0];
1307 p2p_ifp = drvr->iflist[1];
1308
1309 p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif = pri_ifp->vif;
1310
1311 if (p2p_ifp) {
1312 p2p_vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION,
1313 false);
1314 if (IS_ERR(p2p_vif)) {
1315 brcmf_err("could not create discovery vif\n");
1316 err = -ENOMEM;
1317 goto exit;
1318 }
1319
1320 p2p_vif->ifp = p2p_ifp;
1321 p2p_ifp->vif = p2p_vif;
1322 p2p_vif->wdev.netdev = p2p_ifp->ndev;
1323 p2p_ifp->ndev->ieee80211_ptr = &p2p_vif->wdev;
1324 SET_NETDEV_DEV(p2p_ifp->ndev, wiphy_dev(cfg->wiphy));
1325
1326 p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif = p2p_vif;
1327
1328 brcmf_p2p_generate_bss_mac(p2p);
1329 brcmf_p2p_set_firmware(pri_ifp, p2p->dev_addr);
1330
1331 /* Initialize P2P Discovery in the firmware */
1332 err = brcmf_fil_iovar_int_set(pri_ifp, "p2p_disc", 1);
1333 if (err < 0) {
1334 brcmf_err("set p2p_disc error\n");
1335 brcmf_free_vif(p2p_vif);
1336 goto exit;
1337 }
1338 /* obtain bsscfg index for P2P discovery */
1339 err = brcmf_fil_iovar_int_get(pri_ifp, "p2p_dev", &bssidx);
1340 if (err < 0) {
1341 brcmf_err("retrieving discover bsscfg index failed\n");
1342 brcmf_free_vif(p2p_vif);
1343 goto exit;
1344 }
1345 /* Verify that firmware uses same bssidx as driver !! */
1346 if (p2p_ifp->bssidx != bssidx) {
1347 brcmf_err("Incorrect bssidx=%d, compared to p2p_ifp->bssidx=%d\n",
1348 bssidx, p2p_ifp->bssidx);
1349 brcmf_free_vif(p2p_vif);
1350 goto exit;
1351 }
1352
1353 init_completion(&p2p->send_af_done);
1354 }
1355exit:
1356 return err;
9f440b7b
AS
1357}
1358
2fde59d9 1359
9f440b7b
AS
1360/**
1361 * brcmf_p2p_detach() - detach P2P.
1362 *
1363 * @p2p: P2P specific data.
1364 */
1365void brcmf_p2p_detach(struct brcmf_p2p_info *p2p)
1366{
2fde59d9
HM
1367 struct brcmf_cfg80211_vif *vif;
1368
1369 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
1370 if (vif != NULL) {
1371 brcmf_p2p_cancel_remain_on_channel(vif->ifp);
0de8aace 1372 brcmf_p2p_deinit_discovery(p2p);
2fde59d9
HM
1373 /* remove discovery interface */
1374 brcmf_free_vif(vif);
1375 p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif = NULL;
0de8aace 1376 }
9f440b7b
AS
1377 /* just set it all to zero */
1378 memset(p2p, 0, sizeof(*p2p));
1379}
1380
7a5c1f64
HM
1381/**
1382 * brcmf_p2p_get_current_chanspec() - Get current operation channel.
1383 *
1384 * @p2p: P2P specific data.
1385 * @chanspec: chanspec to be returned.
1386 */
1387static void brcmf_p2p_get_current_chanspec(struct brcmf_p2p_info *p2p,
1388 u16 *chanspec)
d3c0b633 1389{
7a5c1f64 1390 struct brcmf_if *ifp;
d3c0b633 1391 struct brcmf_fil_chan_info_le ci;
7a5c1f64
HM
1392 s32 err;
1393
1394 ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
1395
1396 *chanspec = 11 & WL_CHANSPEC_CHAN_MASK;
d3c0b633 1397
d3c0b633
AS
1398 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_CHANNEL, &ci, sizeof(ci));
1399 if (!err) {
7a5c1f64
HM
1400 *chanspec = le32_to_cpu(ci.hw_channel) & WL_CHANSPEC_CHAN_MASK;
1401 if (*chanspec < CH_MAX_2G_CHANNEL)
1402 *chanspec |= WL_CHANSPEC_BAND_2G;
d3c0b633 1403 else
7a5c1f64
HM
1404 *chanspec |= WL_CHANSPEC_BAND_5G;
1405 }
1406 *chanspec |= WL_CHANSPEC_BW_20 | WL_CHANSPEC_CTL_SB_NONE;
1407}
1408
1409/**
1410 * Change a P2P Role.
1411 * Parameters:
1412 * @mac: MAC address of the BSS to change a role
1413 * Returns 0 if success.
1414 */
1415int brcmf_p2p_ifchange(struct brcmf_cfg80211_info *cfg,
1416 enum brcmf_fil_p2p_if_types if_type)
1417{
1418 struct brcmf_p2p_info *p2p = &cfg->p2p;
1419 struct brcmf_cfg80211_vif *vif;
1420 struct brcmf_fil_p2p_if_le if_request;
1421 s32 err;
1422 u16 chanspec;
1423
1424 brcmf_dbg(TRACE, "Enter\n");
1425
1426 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
1427 if (!vif) {
1428 brcmf_err("vif for P2PAPI_BSSCFG_PRIMARY does not exist\n");
1429 return -EPERM;
d3c0b633 1430 }
7a5c1f64
HM
1431 brcmf_notify_escan_complete(cfg, vif->ifp->ndev, true, true);
1432 vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
1433 if (!vif) {
1434 brcmf_err("vif for P2PAPI_BSSCFG_CONNECTION does not exist\n");
1435 return -EPERM;
1436 }
1437 brcmf_set_mpc(vif->ifp->ndev, 0);
1438
1439 /* In concurrency case, STA may be already associated in a particular */
1440 /* channel. so retrieve the current channel of primary interface and */
1441 /* then start the virtual interface on that. */
1442 brcmf_p2p_get_current_chanspec(p2p, &chanspec);
1443
1444 if_request.type = cpu_to_le16((u16)if_type);
1445 if_request.chspec = cpu_to_le16(chanspec);
1446 memcpy(if_request.addr, p2p->int_addr, sizeof(if_request.addr));
1447
1448 brcmf_cfg80211_arm_vif_event(cfg, vif);
1449 err = brcmf_fil_iovar_data_set(vif->ifp, "p2p_ifupd", &if_request,
1450 sizeof(if_request));
1451 if (err) {
1452 brcmf_err("p2p_ifupd FAILED, err=%d\n", err);
1453 brcmf_cfg80211_arm_vif_event(cfg, NULL);
1454 return err;
1455 }
1456 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_CHANGE,
1457 msecs_to_jiffies(1500));
1458 brcmf_cfg80211_arm_vif_event(cfg, NULL);
1459 if (!err) {
1460 brcmf_err("No BRCMF_E_IF_CHANGE event received\n");
1461 return -EIO;
1462 }
1463
1464 err = brcmf_fil_cmd_int_set(vif->ifp, BRCMF_C_SET_SCB_TIMEOUT,
1465 BRCMF_SCB_TIMEOUT_VALUE);
1466
1467 return err;
1468}
1469
1470static int brcmf_p2p_request_p2p_if(struct brcmf_p2p_info *p2p,
1471 struct brcmf_if *ifp, u8 ea[ETH_ALEN],
1472 enum brcmf_fil_p2p_if_types iftype)
1473{
1474 struct brcmf_fil_p2p_if_le if_request;
1475 int err;
1476 u16 chanspec;
1477
1478 /* we need a default channel */
1479 brcmf_p2p_get_current_chanspec(p2p, &chanspec);
d3c0b633
AS
1480
1481 /* fill the firmware request */
1482 memcpy(if_request.addr, ea, ETH_ALEN);
7ee2d926 1483 if_request.type = cpu_to_le16((u16)iftype);
d3c0b633
AS
1484 if_request.chspec = cpu_to_le16(chanspec);
1485
1486 err = brcmf_fil_iovar_data_set(ifp, "p2p_ifadd", &if_request,
1487 sizeof(if_request));
1488 if (err)
1489 return err;
1490
d3c0b633
AS
1491 return err;
1492}
1493
5f4f9f11
AS
1494static int brcmf_p2p_disable_p2p_if(struct brcmf_cfg80211_vif *vif)
1495{
1496 struct brcmf_cfg80211_info *cfg = wdev_to_cfg(&vif->wdev);
1497 struct net_device *pri_ndev = cfg_to_ndev(cfg);
1498 struct brcmf_if *ifp = netdev_priv(pri_ndev);
1499 u8 *addr = vif->wdev.netdev->dev_addr;
1500
1501 return brcmf_fil_iovar_data_set(ifp, "p2p_ifdis", addr, ETH_ALEN);
1502}
1503
1504static int brcmf_p2p_release_p2p_if(struct brcmf_cfg80211_vif *vif)
1505{
1506 struct brcmf_cfg80211_info *cfg = wdev_to_cfg(&vif->wdev);
1507 struct net_device *pri_ndev = cfg_to_ndev(cfg);
1508 struct brcmf_if *ifp = netdev_priv(pri_ndev);
1509 u8 *addr = vif->wdev.netdev->dev_addr;
1510
1511 return brcmf_fil_iovar_data_set(ifp, "p2p_ifdel", addr, ETH_ALEN);
1512}
1513
9f440b7b
AS
1514/**
1515 * brcmf_p2p_add_vif() - create a new P2P virtual interface.
1516 *
1517 * @wiphy: wiphy device of new interface.
1518 * @name: name of the new interface.
1519 * @type: nl80211 interface type.
1520 * @flags: TBD
1521 * @params: TBD
9f440b7b
AS
1522 */
1523struct wireless_dev *brcmf_p2p_add_vif(struct wiphy *wiphy, const char *name,
1524 enum nl80211_iftype type, u32 *flags,
1525 struct vif_params *params)
1526{
d3c0b633
AS
1527 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1528 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
1529 struct brcmf_cfg80211_vif *vif;
1530 enum brcmf_fil_p2p_if_types iftype;
1531 enum wl_mode mode;
1532 int err;
1533
1534 if (brcmf_cfg80211_vif_event_armed(cfg))
1535 return ERR_PTR(-EBUSY);
1536
9f440b7b 1537 brcmf_dbg(INFO, "adding vif \"%s\" (type=%d)\n", name, type);
d3c0b633
AS
1538
1539 switch (type) {
1540 case NL80211_IFTYPE_P2P_CLIENT:
1541 iftype = BRCMF_FIL_P2P_IF_CLIENT;
1542 mode = WL_MODE_BSS;
1543 break;
1544 case NL80211_IFTYPE_P2P_GO:
1545 iftype = BRCMF_FIL_P2P_IF_GO;
1546 mode = WL_MODE_AP;
1547 break;
1548 default:
1549 return ERR_PTR(-EOPNOTSUPP);
1550 }
1551
1552 vif = brcmf_alloc_vif(cfg, type, false);
7ee2d926
HM
1553 if (IS_ERR(vif))
1554 return (struct wireless_dev *)vif;
d3c0b633
AS
1555 brcmf_cfg80211_arm_vif_event(cfg, vif);
1556
7a5c1f64
HM
1557 err = brcmf_p2p_request_p2p_if(&cfg->p2p, ifp, cfg->p2p.int_addr,
1558 iftype);
7ee2d926
HM
1559 if (err) {
1560 brcmf_cfg80211_arm_vif_event(cfg, NULL);
d3c0b633 1561 goto fail;
7ee2d926 1562 }
d3c0b633
AS
1563
1564 /* wait for firmware event */
1565 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_ADD,
1566 msecs_to_jiffies(1500));
1567 brcmf_cfg80211_arm_vif_event(cfg, NULL);
1568 if (!err) {
1569 brcmf_err("timeout occurred\n");
1570 err = -EIO;
1571 goto fail;
1572 }
1573
1574 /* interface created in firmware */
1575 ifp = vif->ifp;
1576 if (!ifp) {
1577 brcmf_err("no if pointer provided\n");
1578 err = -ENOENT;
7ee2d926 1579 goto fail;
d3c0b633
AS
1580 }
1581
1582 strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1);
1583 brcmf_cfg80211_vif_complete(cfg);
7ee2d926
HM
1584 cfg->p2p.bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = vif;
1585 /* Disable firmware roaming for P2P interface */
1586 brcmf_fil_iovar_int_set(ifp, "roam_off", 1);
1587 if (iftype == BRCMF_FIL_P2P_IF_GO) {
1588 /* set station timeout for p2p */
1589 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCB_TIMEOUT,
1590 BRCMF_SCB_TIMEOUT_VALUE);
1591 }
d3c0b633
AS
1592 return &ifp->vif->wdev;
1593
1594fail:
1595 brcmf_free_vif(vif);
1596 return ERR_PTR(err);
9f440b7b
AS
1597}
1598
1599/**
1600 * brcmf_p2p_del_vif() - delete a P2P virtual interface.
1601 *
1602 * @wiphy: wiphy device of interface.
1603 * @wdev: wireless device of interface.
1604 *
1605 * TODO: not yet supported.
1606 */
1607int brcmf_p2p_del_vif(struct wiphy *wiphy, struct wireless_dev *wdev)
1608{
d3c0b633 1609 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
9f440b7b 1610 struct brcmf_cfg80211_vif *vif;
5f4f9f11
AS
1611 unsigned long jiffie_timeout = msecs_to_jiffies(1500);
1612 bool wait_for_disable = false;
d3c0b633 1613 int err;
9f440b7b 1614
5f4f9f11 1615 brcmf_dbg(TRACE, "delete P2P vif\n");
9f440b7b 1616 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
d3c0b633 1617
5f4f9f11
AS
1618 switch (vif->wdev.iftype) {
1619 case NL80211_IFTYPE_P2P_CLIENT:
1620 if (test_bit(BRCMF_VIF_STATUS_DISCONNECTING, &vif->sme_state))
1621 wait_for_disable = true;
1622 break;
1623
1624 case NL80211_IFTYPE_P2P_GO:
1625 if (!brcmf_p2p_disable_p2p_if(vif))
1626 wait_for_disable = true;
1627 break;
1628
1629 case NL80211_IFTYPE_P2P_DEVICE:
1630 default:
1631 return -ENOTSUPP;
1632 break;
1633 }
1634
1635 if (wait_for_disable)
7ee2d926
HM
1636 wait_for_completion_timeout(&cfg->vif_disabled,
1637 msecs_to_jiffies(500));
5f4f9f11
AS
1638
1639 brcmf_vif_clear_mgmt_ies(vif);
d3c0b633
AS
1640
1641 brcmf_cfg80211_arm_vif_event(cfg, vif);
5f4f9f11 1642 err = brcmf_p2p_release_p2p_if(vif);
7ee2d926 1643 if (!err) {
5f4f9f11
AS
1644 /* wait for firmware event */
1645 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_DEL,
1646 jiffie_timeout);
7ee2d926
HM
1647 if (!err)
1648 err = -EIO;
1649 else
1650 err = 0;
1651 }
d3c0b633 1652 brcmf_cfg80211_arm_vif_event(cfg, NULL);
5f4f9f11 1653 brcmf_free_vif(vif);
7ee2d926 1654 cfg->p2p.bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = NULL;
5f4f9f11
AS
1655
1656 return err;
9f440b7b 1657}
This page took 0.094428 seconds and 5 git commands to generate.