blob: aac054cc00690ee2aae47a73d9287b5ff5d3828b [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"
Arend van Sprield3c0b632013-02-08 15:53:37 +010026#include "fwil_types.h"
Arend van Spriel9f440b72013-02-08 15:53:36 +010027#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
Arend van Sprield3c0b632013-02-08 15:53:37 +010049#define BRCMF_SCB_TIMEOUT_VALUE 20
50
Hante Meulemane6da3402013-02-08 15:53:48 +010051#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
Hante Meuleman18e2f612013-02-08 15:53:49 +010058/* 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
Hante Meulemane6da3402013-02-08 15:53:48 +010073/* 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
Arend van Spriel9f440b72013-02-08 15:53:36 +010098/**
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
Arend van Spriel9f440b72013-02-08 15:53:36 +0100141/**
Hante Meulemane6da3402013-02-08 15:53:48 +0100142 * 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
Hante Meuleman18e2f612013-02-08 15:53:49 +0100196/**
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};
Hante Meulemane6da3402013-02-08 15:53:48 +0100207
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
407/**
Arend van Spriel9f440b72013-02-08 15:53:36 +0100408 * brcmf_p2p_set_firmware() - prepare firmware for peer-to-peer operation.
409 *
410 * @p2p: P2P specific data.
411 */
412static int brcmf_p2p_set_firmware(struct brcmf_p2p_info *p2p)
413{
414 struct net_device *ndev = cfg_to_ndev(p2p->cfg);
415 u8 null_eth_addr[] = { 0, 0, 0, 0, 0, 0 };
416 s32 ret = 0;
417
418 brcmf_fil_iovar_int_set(netdev_priv(ndev), "apsta", 1);
419
420 /* In case of COB type, firmware has default mac address
421 * After Initializing firmware, we have to set current mac address to
422 * firmware for P2P device address
423 */
424 ret = brcmf_fil_iovar_data_set(netdev_priv(ndev), "p2p_da_override",
425 null_eth_addr, sizeof(null_eth_addr));
426 if (ret)
427 brcmf_err("failed to update device address ret %d\n", ret);
428
429 return ret;
430}
431
432/**
433 * brcmf_p2p_generate_bss_mac() - derive mac addresses for P2P.
434 *
435 * @p2p: P2P specific data.
436 *
437 * P2P needs mac addresses for P2P device and interface. These are
438 * derived from the primary net device, ie. the permanent ethernet
439 * address of the device.
440 */
441static void brcmf_p2p_generate_bss_mac(struct brcmf_p2p_info *p2p)
442{
Arend van Spriel9f440b72013-02-08 15:53:36 +0100443 /* Generate the P2P Device Address. This consists of the device's
444 * primary MAC address with the locally administered bit set.
445 */
Arend van Sprielde66efc2013-02-08 15:53:40 +0100446 memcpy(p2p->dev_addr, p2p->cfg->pub->mac, ETH_ALEN);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100447 p2p->dev_addr[0] |= 0x02;
448
449 /* Generate the P2P Interface Address. If the discovery and connection
450 * BSSCFGs need to simultaneously co-exist, then this address must be
451 * different from the P2P Device Address, but also locally administered.
452 */
453 memcpy(p2p->int_addr, p2p->dev_addr, ETH_ALEN);
454 p2p->int_addr[4] ^= 0x80;
455}
456
457/**
458 * brcmf_p2p_scan_is_p2p_request() - is cfg80211 scan request a P2P scan.
459 *
460 * @request: the scan request as received from cfg80211.
461 *
462 * returns true if one of the ssids in the request matches the
463 * P2P wildcard ssid; otherwise returns false.
464 */
465static bool brcmf_p2p_scan_is_p2p_request(struct cfg80211_scan_request *request)
466{
467 struct cfg80211_ssid *ssids = request->ssids;
468 int i;
469
470 for (i = 0; i < request->n_ssids; i++) {
471 if (ssids[i].ssid_len != BRCMF_P2P_WILDCARD_SSID_LEN)
472 continue;
473
474 brcmf_dbg(INFO, "comparing ssid \"%s\"", ssids[i].ssid);
475 if (!memcmp(BRCMF_P2P_WILDCARD_SSID, ssids[i].ssid,
476 BRCMF_P2P_WILDCARD_SSID_LEN))
477 return true;
478 }
479 return false;
480}
481
482/**
483 * brcmf_p2p_set_discover_state - set discover state in firmware.
484 *
485 * @ifp: low-level interface object.
486 * @state: discover state to set.
487 * @chanspec: channel parameters (for state @WL_P2P_DISC_ST_LISTEN only).
488 * @listen_ms: duration to listen (for state @WL_P2P_DISC_ST_LISTEN only).
489 */
490static s32 brcmf_p2p_set_discover_state(struct brcmf_if *ifp, u8 state,
491 u16 chanspec, u16 listen_ms)
492{
493 struct brcmf_p2p_disc_st_le discover_state;
494 s32 ret = 0;
495 brcmf_dbg(TRACE, "enter\n");
496
497 discover_state.state = state;
498 discover_state.chspec = cpu_to_le16(chanspec);
499 discover_state.dwell = cpu_to_le16(listen_ms);
500 ret = brcmf_fil_bsscfg_data_set(ifp, "p2p_state", &discover_state,
501 sizeof(discover_state));
502 return ret;
503}
504
505/**
Arend van Spriel9f440b72013-02-08 15:53:36 +0100506 * brcmf_p2p_init_discovery() - enable discovery in the firmware.
507 *
508 * @p2p: P2P specific data.
509 *
510 * Configures the firmware to allow P2P peer discovery. Creates the
511 * virtual interface and consequently the P2P device for it.
512 */
513static s32 brcmf_p2p_init_discovery(struct brcmf_p2p_info *p2p)
514{
515 struct net_device *ndev = cfg_to_ndev(p2p->cfg);
516 struct brcmf_cfg80211_vif *vif;
517 struct brcmf_if *ifp;
518 struct p2p_bss *bss_dev;
519 s32 index;
520 s32 ret;
521
522 brcmf_dbg(TRACE, "enter\n");
523
524 bss_dev = &p2p->bss_idx[P2PAPI_BSSCFG_DEVICE];
525 if (bss_dev->vif != NULL) {
526 brcmf_dbg(INFO, "do nothing, already initialized\n");
527 return 0;
528 }
529
530 /* Enable P2P Discovery in the firmware */
531 ret = brcmf_fil_iovar_int_set(netdev_priv(ndev), "p2p_disc", 1);
532 if (ret < 0) {
533 brcmf_err("set discover error\n");
534 return ret;
535 }
536
537 /* obtain bsscfg index for P2P discovery */
538 ret = brcmf_fil_iovar_int_get(netdev_priv(ndev), "p2p_dev", &index);
539 if (ret < 0) {
540 brcmf_err("retrieving discover bsscfg index failed\n");
541 return ret;
542 }
543
544 /*
545 * need brcmf_if for setting the discovery state.
546 */
547 ifp = kzalloc(sizeof(*vif->ifp), GFP_KERNEL);
548 if (!ifp) {
549 brcmf_err("could not create discovery if\n");
550 return -ENOMEM;
551 }
552
553 /* set required fields */
554 ifp->drvr = p2p->cfg->pub;
555 ifp->ifidx = 0;
556 ifp->bssidx = index;
557
558 /* Set the initial discovery state to SCAN */
559 ret = brcmf_p2p_set_discover_state(ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
560
561 if (ret != 0) {
562 brcmf_err("unable to set WL_P2P_DISC_ST_SCAN\n");
563 (void)brcmf_fil_iovar_int_set(netdev_priv(ndev), "p2p_disc", 0);
564 kfree(ifp);
565 return ret;
566 }
567
568 /* create a vif for it */
Arend van Sprield3c0b632013-02-08 15:53:37 +0100569 vif = brcmf_alloc_vif(p2p->cfg, NL80211_IFTYPE_P2P_DEVICE, false);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100570 if (IS_ERR(vif)) {
571 brcmf_err("could not create discovery vif\n");
572 kfree(ifp);
573 return PTR_ERR(vif);
574 }
575
576 vif->ifp = ifp;
577 ifp->vif = vif;
578 bss_dev->vif = vif;
579
580 return 0;
581}
582
583/**
584 * brcmf_p2p_deinit_discovery() - disable P2P device discovery.
585 *
586 * @p2p: P2P specific data.
587 *
588 * Resets the discovery state and disables it in firmware. The virtual
589 * interface and P2P device are freed.
590 */
591static s32 brcmf_p2p_deinit_discovery(struct brcmf_p2p_info *p2p)
592{
593 struct net_device *ndev = cfg_to_ndev(p2p->cfg);
594 struct brcmf_if *ifp;
595 struct p2p_bss *bss_dev;
596 brcmf_dbg(TRACE, "enter\n");
597
598 bss_dev = &p2p->bss_idx[P2PAPI_BSSCFG_DEVICE];
Arend van Spriel9f440b72013-02-08 15:53:36 +0100599 ifp = bss_dev->vif->ifp;
600
601 /* Set the discovery state to SCAN */
602 (void)brcmf_p2p_set_discover_state(ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
603
604 /* Disable P2P discovery in the firmware */
605 (void)brcmf_fil_iovar_int_set(netdev_priv(ndev), "p2p_disc", 0);
606
607 /* remove discovery interface */
608 brcmf_free_vif(bss_dev->vif);
609 bss_dev->vif = NULL;
610 kfree(ifp);
611
612 return 0;
613}
614
615/**
616 * brcmf_p2p_enable_discovery() - initialize and configure discovery.
617 *
618 * @p2p: P2P specific data.
Arend van Spriel9f440b72013-02-08 15:53:36 +0100619 *
620 * Initializes the discovery device and configure the virtual interface.
621 */
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100622static int brcmf_p2p_enable_discovery(struct brcmf_p2p_info *p2p)
Arend van Spriel9f440b72013-02-08 15:53:36 +0100623{
624 struct brcmf_cfg80211_vif *vif;
625 s32 ret = 0;
626
627 brcmf_dbg(TRACE, "enter\n");
628 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
629 if (vif) {
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100630 brcmf_dbg(INFO, "DISCOVERY init already done\n");
631 goto exit;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100632 }
633
634 ret = brcmf_p2p_init_discovery(p2p);
635 if (ret < 0) {
636 brcmf_err("init discovery error %d\n", ret);
637 goto exit;
638 }
639
640 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
641
642 /*
643 * Set wsec to any non-zero value in the discovery bsscfg
644 * to ensure our P2P probe responses have the privacy bit
645 * set in the 802.11 WPA IE. Some peer devices may not
646 * initiate WPS with us if this bit is not set.
647 */
648 ret = brcmf_fil_bsscfg_int_set(vif->ifp, "wsec", AES_ENABLED);
649 if (ret < 0)
650 brcmf_err("wsec error %d\n", ret);
651
Arend van Spriel9f440b72013-02-08 15:53:36 +0100652exit:
653 return ret;
654}
655
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100656/**
Arend van Spriel9f440b72013-02-08 15:53:36 +0100657 * brcmf_p2p_escan() - initiate a P2P scan.
658 *
659 * @p2p: P2P specific data.
660 * @num_chans: number of channels to scan.
661 * @chanspecs: channel parameters for @num_chans channels.
662 * @search_state: P2P discover state to use.
663 * @action: scan action to pass to firmware.
664 * @bss_type: type of P2P bss.
665 */
666static s32 brcmf_p2p_escan(struct brcmf_p2p_info *p2p, u32 num_chans,
667 u16 chanspecs[], s32 search_state, u16 action,
668 enum p2p_bss_type bss_type)
669{
670 s32 ret = 0;
671 s32 memsize = offsetof(struct brcmf_p2p_scan_le,
672 eparams.params_le.channel_list);
673 s32 nprobes;
674 s32 active;
675 u32 i;
676 u8 *memblk;
677 struct brcmf_cfg80211_vif *vif;
678 struct brcmf_p2p_scan_le *p2p_params;
679 struct brcmf_scan_params_le *sparams;
680 struct brcmf_ssid ssid;
681
Arend van Spriel9f440b72013-02-08 15:53:36 +0100682 memsize += num_chans * sizeof(__le16);
683 memblk = kzalloc(memsize, GFP_KERNEL);
684 if (!memblk)
685 return -ENOMEM;
686
687 vif = p2p->bss_idx[bss_type].vif;
688 if (vif == NULL) {
689 brcmf_err("no vif for bss type %d\n", bss_type);
690 ret = -EINVAL;
691 goto exit;
692 }
693
694 switch (search_state) {
695 case WL_P2P_DISC_ST_SEARCH:
696 /*
697 * If we in SEARCH STATE, we don't need to set SSID explictly
698 * because dongle use P2P WILDCARD internally by default
699 */
700 /* use null ssid */
701 ssid.SSID_len = 0;
702 memset(ssid.SSID, 0, sizeof(ssid.SSID));
703 break;
704 case WL_P2P_DISC_ST_SCAN:
705 /*
706 * wpa_supplicant has p2p_find command with type social or
707 * progressive. For progressive, we need to set the ssid to
708 * P2P WILDCARD because we just do broadcast scan unless
709 * setting SSID.
710 */
711 ssid.SSID_len = BRCMF_P2P_WILDCARD_SSID_LEN;
712 memcpy(ssid.SSID, BRCMF_P2P_WILDCARD_SSID, ssid.SSID_len);
713 break;
714 default:
715 brcmf_err(" invalid search state %d\n", search_state);
716 ret = -EINVAL;
717 goto exit;
718 }
719
720 brcmf_p2p_set_discover_state(vif->ifp, search_state, 0, 0);
721
722 /*
723 * set p2p scan parameters.
724 */
725 p2p_params = (struct brcmf_p2p_scan_le *)memblk;
726 p2p_params->type = 'E';
727
728 /* determine the scan engine parameters */
729 sparams = &p2p_params->eparams.params_le;
730 sparams->bss_type = DOT11_BSSTYPE_ANY;
731 if (p2p->cfg->active_scan)
732 sparams->scan_type = 0;
733 else
734 sparams->scan_type = 1;
735
736 memset(&sparams->bssid, 0xFF, ETH_ALEN);
737 if (ssid.SSID_len)
738 memcpy(sparams->ssid_le.SSID, ssid.SSID, ssid.SSID_len);
739 sparams->ssid_le.SSID_len = cpu_to_le32(ssid.SSID_len);
740 sparams->home_time = cpu_to_le32(P2PAPI_SCAN_HOME_TIME_MS);
741
742 /*
743 * SOCIAL_CHAN_CNT + 1 takes care of the Progressive scan
744 * supported by the supplicant.
745 */
746 if (num_chans == SOCIAL_CHAN_CNT || num_chans == (SOCIAL_CHAN_CNT + 1))
747 active = P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS;
748 else if (num_chans == AF_PEER_SEARCH_CNT)
749 active = P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS;
750 else if (wl_get_vif_state_all(p2p->cfg, BRCMF_VIF_STATUS_CONNECTED))
751 active = -1;
752 else
753 active = P2PAPI_SCAN_DWELL_TIME_MS;
754
755 /* Override scan params to find a peer for a connection */
756 if (num_chans == 1) {
757 active = WL_SCAN_CONNECT_DWELL_TIME_MS;
Hante Meuleman18e2f612013-02-08 15:53:49 +0100758 /* WAR to sync with presence period of VSDB GO.
Arend van Spriel9f440b72013-02-08 15:53:36 +0100759 * send probe request more frequently
760 */
761 nprobes = active / WL_SCAN_JOIN_PROBE_INTERVAL_MS;
762 } else {
763 nprobes = active / P2PAPI_SCAN_NPROBS_TIME_MS;
764 }
765
766 if (nprobes <= 0)
767 nprobes = 1;
768
769 brcmf_dbg(INFO, "nprobes # %d, active_time %d\n", nprobes, active);
770 sparams->active_time = cpu_to_le32(active);
771 sparams->nprobes = cpu_to_le32(nprobes);
772 sparams->passive_time = cpu_to_le32(-1);
773 sparams->channel_num = cpu_to_le32(num_chans &
774 BRCMF_SCAN_PARAMS_COUNT_MASK);
775 for (i = 0; i < num_chans; i++)
776 sparams->channel_list[i] = cpu_to_le16(chanspecs[i]);
777
778 /* set the escan specific parameters */
779 p2p_params->eparams.version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION);
780 p2p_params->eparams.action = cpu_to_le16(action);
781 p2p_params->eparams.sync_id = cpu_to_le16(0x1234);
782 /* perform p2p scan on primary device */
783 ret = brcmf_fil_bsscfg_data_set(vif->ifp, "p2p_scan", memblk, memsize);
784 if (!ret)
785 set_bit(BRCMF_SCAN_STATUS_BUSY, &p2p->cfg->scan_status);
786exit:
787 kfree(memblk);
788 return ret;
789}
790
791/**
792 * brcmf_p2p_run_escan() - escan callback for peer-to-peer.
793 *
794 * @cfg: driver private data for cfg80211 interface.
795 * @ndev: net device for which scan is requested.
796 * @request: scan request from cfg80211.
797 * @action: scan action.
798 *
799 * Determines the P2P discovery state based to scan request parameters and
800 * validates the channels in the request.
801 */
802static s32 brcmf_p2p_run_escan(struct brcmf_cfg80211_info *cfg,
803 struct net_device *ndev,
804 struct cfg80211_scan_request *request,
805 u16 action)
806{
807 struct brcmf_p2p_info *p2p = &cfg->p2p;
808 s32 err = 0;
809 s32 search_state = WL_P2P_DISC_ST_SCAN;
810 struct brcmf_cfg80211_vif *vif;
811 struct net_device *dev = NULL;
812 int i, num_nodfs = 0;
813 u16 *chanspecs;
814
815 brcmf_dbg(TRACE, "enter\n");
816
817 if (!request) {
818 err = -EINVAL;
819 goto exit;
820 }
821
822 if (request->n_channels) {
823 chanspecs = kcalloc(request->n_channels, sizeof(*chanspecs),
824 GFP_KERNEL);
825 if (!chanspecs) {
826 err = -ENOMEM;
827 goto exit;
828 }
829 vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
830 if (vif)
831 dev = vif->wdev.netdev;
832 if (request->n_channels == 3 &&
833 request->channels[0]->hw_value == SOCIAL_CHAN_1 &&
834 request->channels[1]->hw_value == SOCIAL_CHAN_2 &&
835 request->channels[2]->hw_value == SOCIAL_CHAN_3) {
836 /* SOCIAL CHANNELS 1, 6, 11 */
837 search_state = WL_P2P_DISC_ST_SEARCH;
838 brcmf_dbg(INFO, "P2P SEARCH PHASE START\n");
839 } else if (dev != NULL && vif->mode == WL_MODE_AP) {
840 /* If you are already a GO, then do SEARCH only */
841 brcmf_dbg(INFO, "Already a GO. Do SEARCH Only\n");
842 search_state = WL_P2P_DISC_ST_SEARCH;
843 } else {
844 brcmf_dbg(INFO, "P2P SCAN STATE START\n");
845 }
846
847 /*
848 * no P2P scanning on passive or DFS channels.
849 */
850 for (i = 0; i < request->n_channels; i++) {
851 struct ieee80211_channel *chan = request->channels[i];
852
853 if (chan->flags & (IEEE80211_CHAN_RADAR |
854 IEEE80211_CHAN_PASSIVE_SCAN))
855 continue;
856
857 chanspecs[i] = channel_to_chanspec(chan);
858 brcmf_dbg(INFO, "%d: chan=%d, channel spec=%x\n",
859 num_nodfs, chan->hw_value, chanspecs[i]);
860 num_nodfs++;
861 }
862 err = brcmf_p2p_escan(p2p, num_nodfs, chanspecs, search_state,
863 action, P2PAPI_BSSCFG_DEVICE);
864 }
865exit:
866 if (err)
867 brcmf_err("error (%d)\n", err);
868 return err;
869}
870
871/**
872 * brcmf_p2p_scan_prep() - prepare scan based on request.
873 *
874 * @wiphy: wiphy device.
875 * @request: scan request from cfg80211.
Hante Meuleman0f8ffe12013-02-08 15:53:42 +0100876 * @vif: vif on which scan request is to be executed.
Arend van Spriel9f440b72013-02-08 15:53:36 +0100877 *
878 * Prepare the scan appropriately for type of scan requested. Overrides the
879 * escan .run() callback for peer-to-peer scanning.
880 */
881int brcmf_p2p_scan_prep(struct wiphy *wiphy,
Hante Meuleman0f8ffe12013-02-08 15:53:42 +0100882 struct cfg80211_scan_request *request,
883 struct brcmf_cfg80211_vif *vif)
Arend van Spriel9f440b72013-02-08 15:53:36 +0100884{
885 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
886 struct brcmf_p2p_info *p2p = &cfg->p2p;
887 int err = 0;
888
889 if (brcmf_p2p_scan_is_p2p_request(request)) {
890 /* find my listen channel */
891 err = cfg80211_get_p2p_attr(request->ie, request->ie_len,
892 IEEE80211_P2P_ATTR_LISTEN_CHANNEL,
893 &p2p->listen_channel, 1);
894 if (err < 0)
895 return err;
896
897 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
898 brcmf_dbg(INFO, "P2P: GO_NEG_PHASE status cleared\n");
899
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100900 err = brcmf_p2p_enable_discovery(p2p);
Hante Meuleman0f8ffe12013-02-08 15:53:42 +0100901 if (err)
902 return err;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100903
Hante Meuleman0f8ffe12013-02-08 15:53:42 +0100904 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
905
906 /* override .run_escan() callback. */
Arend van Spriel9f440b72013-02-08 15:53:36 +0100907 cfg->escan_info.run = brcmf_p2p_run_escan;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100908 }
Hante Meuleman0f8ffe12013-02-08 15:53:42 +0100909 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBREQ_FLAG,
910 request->ie, request->ie_len);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100911 return err;
912}
913
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100914
915/**
Hante Meulemanf2058dd2013-02-08 15:53:50 +0100916 * brcmf_p2p_discover_listen() - set firmware to discover listen state.
917 *
918 * @p2p: p2p device.
919 * @freq: center frequency for discover listen.
920 * #@duration: time in ms to stay on channel.
921 *
922 */
923static s32
924brcmf_p2p_discover_listen(struct brcmf_p2p_info *p2p,
925 struct ieee80211_channel *channel, u32 duration)
926{
927 struct brcmf_cfg80211_vif *vif;
928 s32 err = 0;
929 u16 chanspec;
930
931 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
932 if (!vif) {
933 brcmf_err("Discovery is not set, so we have nothing to do\n");
934 err = -EPERM;
935 goto exit;
936 }
937
938 if (test_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status)) {
939 brcmf_err("Previous LISTEN is not completed yet\n");
940 /* WAR: prevent cookie mismatch in wpa_supplicant return OK */
941 goto exit;
942 }
943
944 chanspec = channel_to_chanspec(channel);
945 err = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_LISTEN,
946 chanspec, (u16)duration);
947 if (!err) {
948 set_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status);
949 p2p->remain_on_channel_cookie++;
950 }
951exit:
952 return err;
953}
954
955
956/**
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100957 * brcmf_p2p_remain_on_channel() - put device on channel and stay there.
958 *
959 * @wiphy: wiphy device.
960 * @channel: channel to stay on.
961 * @duration: time in ms to remain on channel.
962 *
963 */
964int brcmf_p2p_remain_on_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
965 struct ieee80211_channel *channel,
966 unsigned int duration, u64 *cookie)
967{
968 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
969 struct brcmf_p2p_info *p2p = &cfg->p2p;
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100970 s32 err;
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100971
972 brcmf_dbg(TRACE, "Enter, channel: %d, duration ms (%d)\n",
973 ieee80211_frequency_to_channel(channel->center_freq),
974 duration);
975
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100976 err = brcmf_p2p_enable_discovery(p2p);
977 if (err)
978 goto exit;
Hante Meulemanf2058dd2013-02-08 15:53:50 +0100979 err = brcmf_p2p_discover_listen(p2p, channel, duration);
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100980 if (err)
981 goto exit;
982
Hante Meulemanf2058dd2013-02-08 15:53:50 +0100983 memcpy(&p2p->remain_on_channel, channel, sizeof(*channel));
984 *cookie = p2p->remain_on_channel_cookie;
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100985
986exit:
987 cfg80211_ready_on_channel(wdev, *cookie, channel, duration, GFP_KERNEL);
988 return err;
989}
990
991
992/**
993 * brcmf_p2p_notify_listen_complete() - p2p listen has completed.
994 *
995 * @ifp: interfac control.
996 * @e: event message. Not used, to make it usable for fweh event dispatcher.
997 * @data: payload of message. Not used.
998 *
999 */
1000int brcmf_p2p_notify_listen_complete(struct brcmf_if *ifp,
1001 const struct brcmf_event_msg *e,
1002 void *data)
1003{
1004 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
1005 struct brcmf_p2p_info *p2p = &cfg->p2p;
1006
1007 brcmf_dbg(TRACE, "Enter\n");
Hante Meulemanf2058dd2013-02-08 15:53:50 +01001008 if (test_and_clear_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN,
Hante Meuleman0de8aac2013-02-08 15:53:38 +01001009 &p2p->status))
Hante Meulemanf2058dd2013-02-08 15:53:50 +01001010 cfg80211_remain_on_channel_expired(&ifp->vif->wdev,
1011 p2p->remain_on_channel_cookie,
Hante Meuleman0de8aac2013-02-08 15:53:38 +01001012 &p2p->remain_on_channel,
1013 GFP_KERNEL);
1014 return 0;
1015}
1016
1017
1018/**
1019 * brcmf_p2p_cancel_remain_on_channel() - cancel p2p listen state.
1020 *
1021 * @ifp: interfac control.
1022 *
1023 */
1024void brcmf_p2p_cancel_remain_on_channel(struct brcmf_if *ifp)
1025{
1026 if (!ifp)
1027 return;
1028 brcmf_p2p_set_discover_state(ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
1029 brcmf_p2p_notify_listen_complete(ifp, NULL, NULL);
1030}
1031
1032
Arend van Spriel9f440b72013-02-08 15:53:36 +01001033/**
Hante Meulemane6da3402013-02-08 15:53:48 +01001034 * brcmf_p2p_notify_action_frame_rx() - received action frame.
1035 *
1036 * @ifp: interfac control.
1037 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1038 * @data: payload of message, containing action frame data.
1039 *
1040 */
1041int brcmf_p2p_notify_action_frame_rx(struct brcmf_if *ifp,
1042 const struct brcmf_event_msg *e,
1043 void *data)
1044{
1045 struct wireless_dev *wdev;
1046 u32 mgmt_frame_len = e->datalen - sizeof(struct brcmf_rx_mgmt_data);
1047 struct brcmf_rx_mgmt_data *rxframe = (struct brcmf_rx_mgmt_data *)data;
1048 u16 chanspec = be16_to_cpu(rxframe->chanspec);
1049 struct ieee80211_mgmt *mgmt_frame;
1050 s32 err;
1051 s32 freq;
1052 u16 mgmt_type;
1053
1054 /* Check if wpa_supplicant has registered for this frame */
1055 brcmf_dbg(INFO, "ifp->vif->mgmt_rx_reg %04x\n", ifp->vif->mgmt_rx_reg);
1056 mgmt_type = (IEEE80211_STYPE_ACTION & IEEE80211_FCTL_STYPE) >> 4;
1057 if ((ifp->vif->mgmt_rx_reg & BIT(mgmt_type)) == 0)
1058 return 0;
1059
1060 brcmf_p2p_print_actframe(false, (u8 *)(rxframe + 1), mgmt_frame_len);
1061
1062 mgmt_frame = kzalloc(offsetof(struct ieee80211_mgmt, u) +
1063 mgmt_frame_len, GFP_KERNEL);
1064 if (!mgmt_frame) {
1065 brcmf_err("No memory available for action frame\n");
1066 return -ENOMEM;
1067 }
1068 memcpy(mgmt_frame->da, ifp->mac_addr, ETH_ALEN);
1069 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSSID, mgmt_frame->bssid,
1070 ETH_ALEN);
1071 if (err < 0)
1072 brcmf_err("BRCMF_C_GET_BSSID error %d\n", err);
1073 memcpy(mgmt_frame->sa, e->addr, ETH_ALEN);
1074 mgmt_frame->frame_control = cpu_to_le16(IEEE80211_STYPE_ACTION);
1075 memcpy(&mgmt_frame->u, (u8 *)(rxframe + 1), mgmt_frame_len);
1076 mgmt_frame_len += offsetof(struct ieee80211_mgmt, u);
1077
1078 freq = ieee80211_channel_to_frequency(CHSPEC_CHANNEL(chanspec),
1079 CHSPEC_IS2G(chanspec) ?
1080 IEEE80211_BAND_2GHZ :
1081 IEEE80211_BAND_5GHZ);
1082 wdev = ifp->ndev->ieee80211_ptr;
1083 cfg80211_rx_mgmt(wdev, freq, 0, (u8 *)mgmt_frame, mgmt_frame_len,
1084 GFP_ATOMIC);
1085
1086 kfree(mgmt_frame);
1087 return 0;
1088}
1089
1090
1091/**
Hante Meuleman18e2f612013-02-08 15:53:49 +01001092 * brcmf_p2p_notify_action_tx_complete() - transmit action frame complete
1093 *
1094 * @ifp: interfac control.
1095 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1096 * @data: not used.
1097 *
1098 */
1099int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp,
1100 const struct brcmf_event_msg *e,
1101 void *data)
1102{
1103 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
1104 struct brcmf_p2p_info *p2p = &cfg->p2p;
1105
1106 brcmf_dbg(INFO, "Enter: status %d\n", e->status);
1107
1108 if (e->status == BRCMF_E_STATUS_SUCCESS)
1109 set_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
1110 else
1111 set_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
1112 /* for now complete the receiver process here !! */
1113 complete(&p2p->send_af_done);
1114
1115 return 0;
1116}
1117
1118
1119/**
1120 * brcmf_p2p_tx_action_frame() - send action frame over fil.
1121 *
1122 * @p2p: p2p info struct for vif.
1123 * @af_params: action frame data/info.
1124 *
1125 * Send an action frame immediately without doing channel synchronization.
1126 *
1127 * This function waits for a completion event before returning.
1128 * The WLC_E_ACTION_FRAME_COMPLETE event will be received when the action
1129 * frame is transmitted.
1130 */
1131static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p,
1132 struct brcmf_fil_af_params_le *af_params)
1133{
1134 struct brcmf_cfg80211_vif *vif;
1135 s32 err = 0;
1136 s32 timeout = 0;
1137
1138 brcmf_dbg(TRACE, "Enter\n");
1139
1140 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
1141 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
1142
1143 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
1144 err = brcmf_fil_bsscfg_data_set(vif->ifp, "actframe", af_params,
1145 sizeof(*af_params));
1146 if (err) {
1147 brcmf_err(" sending action frame has failed\n");
1148 goto exit;
1149 }
1150
1151 timeout = wait_for_completion_timeout(&p2p->send_af_done,
1152 msecs_to_jiffies(P2P_AF_MAX_WAIT_TIME));
1153
1154 if (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status)) {
1155 brcmf_dbg(TRACE, "TX action frame operation is success\n");
1156 } else {
1157 err = -EIO;
1158 brcmf_dbg(TRACE, "TX action frame operation has failed\n");
1159 }
1160 /* clear status bit for action tx */
1161 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
1162 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
1163
1164exit:
1165 return err;
1166}
1167
1168
1169/**
1170 * brcmf_p2p_pub_af_tx() - public action frame tx routine.
1171 *
1172 * @cfg: driver private data for cfg80211 interface.
1173 * @af_params: action frame data/info.
1174 * @config_af_params: configuration data for action frame.
1175 *
1176 * routine which transmits ation frame public type.
1177 */
1178static s32 brcmf_p2p_pub_af_tx(struct brcmf_cfg80211_info *cfg,
1179 struct brcmf_fil_af_params_le *af_params,
1180 struct brcmf_config_af_params *config_af_params)
1181{
1182 struct brcmf_p2p_info *p2p = &cfg->p2p;
1183 struct brcmf_fil_action_frame_le *action_frame;
1184 struct brcmf_p2p_pub_act_frame *act_frm;
1185 s32 err = 0;
1186
1187 action_frame = &af_params->action_frame;
1188 act_frm = (struct brcmf_p2p_pub_act_frame *)(action_frame->data);
1189
1190 switch (act_frm->subtype) {
1191 case P2P_PAF_GON_REQ:
1192 brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status set\n");
1193 set_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
1194 config_af_params->mpc_onoff = 0;
1195 p2p->next_af_subtype = act_frm->subtype + 1;
1196 /* increase dwell time to wait for RESP frame */
1197 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1198 break;
1199 case P2P_PAF_GON_RSP:
1200 p2p->next_af_subtype = act_frm->subtype + 1;
1201 /* increase dwell time to wait for CONF frame */
1202 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1203 break;
1204 case P2P_PAF_GON_CONF:
1205 /* If we reached till GO Neg confirmation reset the filter */
1206 brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status cleared\n");
1207 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
1208 /* turn on mpc again if go nego is done */
1209 config_af_params->mpc_onoff = 1;
1210 /* minimize dwell time */
1211 af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1212 break;
1213 case P2P_PAF_INVITE_REQ:
1214 p2p->next_af_subtype = act_frm->subtype + 1;
1215 /* increase dwell time */
1216 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1217 break;
1218 case P2P_PAF_INVITE_RSP:
1219 /* minimize dwell time */
1220 af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1221 break;
1222 case P2P_PAF_DEVDIS_REQ:
1223 p2p->next_af_subtype = act_frm->subtype + 1;
1224 /* maximize dwell time to wait for RESP frame */
1225 af_params->dwell_time = cpu_to_le32(P2P_AF_LONG_DWELL_TIME);
1226 break;
1227 case P2P_PAF_DEVDIS_RSP:
1228 /* minimize dwell time */
1229 af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1230 break;
1231 case P2P_PAF_PROVDIS_REQ:
1232 config_af_params->mpc_onoff = 0;
1233 p2p->next_af_subtype = act_frm->subtype + 1;
1234 /* increase dwell time to wait for RESP frame */
1235 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1236 break;
1237 case P2P_PAF_PROVDIS_RSP:
1238 /* wpa_supplicant send go nego req right after prov disc */
1239 p2p->next_af_subtype = P2P_PAF_GON_REQ;
1240 /* increase dwell time to MED level */
1241 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1242 break;
1243 default:
1244 brcmf_err("Unknown p2p pub act frame subtype: %d\n",
1245 act_frm->subtype);
1246 err = -EINVAL;
1247 }
1248 return err;
1249}
1250
1251/**
1252 * brcmf_p2p_send_action_frame() - send action frame .
1253 *
1254 * @cfg: driver private data for cfg80211 interface.
1255 * @ndev: net device to transmit on.
1256 * @af_params: configuration data for action frame.
1257 */
1258bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info *cfg,
1259 struct net_device *ndev,
1260 struct brcmf_fil_af_params_le *af_params)
1261{
1262 struct brcmf_p2p_info *p2p = &cfg->p2p;
1263 struct brcmf_fil_action_frame_le *action_frame;
1264 struct brcmf_config_af_params config_af_params;
1265 u16 action_frame_len;
1266 bool ack = false;
1267 u8 category;
1268 u8 action;
1269 s32 tx_retry;
1270
1271 action_frame = &af_params->action_frame;
1272 action_frame_len = le16_to_cpu(action_frame->len);
1273
1274 brcmf_p2p_print_actframe(true, action_frame->data, action_frame_len);
1275
1276 /* Add the default dwell time. Dwell time to stay off-channel */
1277 /* to wait for a response action frame after transmitting an */
1278 /* GO Negotiation action frame */
1279 af_params->dwell_time = cpu_to_le32(P2P_AF_DWELL_TIME);
1280
1281 category = action_frame->data[DOT11_ACTION_CAT_OFF];
1282 action = action_frame->data[DOT11_ACTION_ACT_OFF];
1283
1284 /* initialize variables */
1285 p2p->next_af_subtype = P2P_PAF_SUBTYPE_INVALID;
1286
1287 /* config parameters */
1288 config_af_params.max_tx_retry = P2P_AF_TX_MAX_RETRY;
1289 config_af_params.mpc_onoff = -1;
1290
1291 if (brcmf_p2p_is_pub_action(action_frame->data, action_frame_len)) {
1292 /* p2p public action frame process */
1293 if (brcmf_p2p_pub_af_tx(cfg, af_params, &config_af_params)) {
1294 /* Just send unknown subtype frame with */
1295 /* default parameters. */
1296 brcmf_err("P2P Public action frame, unknown subtype.\n");
1297 }
1298 } else if (brcmf_p2p_is_gas_action(action_frame->data,
1299 action_frame_len)) {
1300 /* service discovery process */
1301 if (action == P2PSD_ACTION_ID_GAS_IREQ ||
1302 action == P2PSD_ACTION_ID_GAS_CREQ) {
1303 /* save next af suptype to cancel */
1304 /* remaining dwell time */
1305 p2p->next_af_subtype = action + 1;
1306
1307 af_params->dwell_time =
1308 cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1309 } else if (action == P2PSD_ACTION_ID_GAS_IRESP ||
1310 action == P2PSD_ACTION_ID_GAS_CRESP) {
1311 /* configure service discovery response frame */
1312 af_params->dwell_time =
1313 cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1314 } else {
1315 brcmf_err("Unknown action type: %d\n", action);
1316 goto exit;
1317 }
1318 } else if (brcmf_p2p_is_p2p_action(action_frame->data,
1319 action_frame_len)) {
1320 /* do not configure anything. it will be */
1321 /* sent with a default configuration */
1322 } else {
1323 brcmf_err("Unknown Frame: category 0x%x, action 0x%x\n",
1324 category, action);
1325 return false;
1326 }
1327
1328 /* if scan is ongoing, abort current scan. */
1329 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
1330 brcmf_abort_scanning(cfg);
1331
1332 /* To make sure to send successfully action frame, turn off mpc */
1333 if (config_af_params.mpc_onoff == 0)
1334 brcmf_set_mpc(ndev, 0);
1335
1336 /* if failed, retry it. tx_retry_max value is configure by .... */
1337 tx_retry = 0;
1338 while ((ack == false) && (tx_retry < config_af_params.max_tx_retry)) {
1339 ack = !brcmf_p2p_tx_action_frame(p2p, af_params);
1340 tx_retry++;
1341 }
1342 if (ack == false)
1343 brcmf_err("Failed to send Action Frame(retry %d)\n", tx_retry);
1344
1345exit:
1346 /* if all done, turn mpc on again */
1347 if (config_af_params.mpc_onoff == 1)
1348 brcmf_set_mpc(ndev, 1);
1349
1350 return ack;
1351}
1352
1353
1354/**
Arend van Spriel9f440b72013-02-08 15:53:36 +01001355 * brcmf_p2p_attach() - attach for P2P.
1356 *
1357 * @cfg: driver private data for cfg80211 interface.
1358 */
Hante Meulemana0f07952013-02-08 15:53:47 +01001359void brcmf_p2p_attach(struct brcmf_cfg80211_info *cfg,
1360 struct brcmf_cfg80211_vif *vif)
Arend van Spriel9f440b72013-02-08 15:53:36 +01001361{
1362 struct brcmf_p2p_info *p2p;
1363
1364 p2p = &cfg->p2p;
1365
1366 p2p->cfg = cfg;
Hante Meulemana0f07952013-02-08 15:53:47 +01001367 p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif = vif;
Arend van Spriel9f440b72013-02-08 15:53:36 +01001368 brcmf_p2p_generate_bss_mac(p2p);
Hante Meulemana0f07952013-02-08 15:53:47 +01001369 brcmf_p2p_set_firmware(p2p);
Hante Meuleman18e2f612013-02-08 15:53:49 +01001370 init_completion(&p2p->send_af_done);
Arend van Spriel9f440b72013-02-08 15:53:36 +01001371}
1372
1373/**
1374 * brcmf_p2p_detach() - detach P2P.
1375 *
1376 * @p2p: P2P specific data.
1377 */
1378void brcmf_p2p_detach(struct brcmf_p2p_info *p2p)
1379{
Hante Meuleman0de8aac2013-02-08 15:53:38 +01001380 if (p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif != NULL) {
1381 brcmf_p2p_cancel_remain_on_channel(
1382 p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif->ifp);
1383 brcmf_p2p_deinit_discovery(p2p);
1384 }
Arend van Spriel9f440b72013-02-08 15:53:36 +01001385 /* just set it all to zero */
1386 memset(p2p, 0, sizeof(*p2p));
1387}
1388
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01001389/**
1390 * brcmf_p2p_get_current_chanspec() - Get current operation channel.
1391 *
1392 * @p2p: P2P specific data.
1393 * @chanspec: chanspec to be returned.
1394 */
1395static void brcmf_p2p_get_current_chanspec(struct brcmf_p2p_info *p2p,
1396 u16 *chanspec)
1397{
1398 struct brcmf_if *ifp;
1399 struct brcmf_fil_chan_info_le ci;
1400 s32 err;
1401
1402 ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
1403
1404 *chanspec = 11 & WL_CHANSPEC_CHAN_MASK;
1405
1406 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_CHANNEL, &ci, sizeof(ci));
1407 if (!err) {
1408 *chanspec = le32_to_cpu(ci.hw_channel) & WL_CHANSPEC_CHAN_MASK;
1409 if (*chanspec < CH_MAX_2G_CHANNEL)
1410 *chanspec |= WL_CHANSPEC_BAND_2G;
1411 else
1412 *chanspec |= WL_CHANSPEC_BAND_5G;
1413 }
1414 *chanspec |= WL_CHANSPEC_BW_20 | WL_CHANSPEC_CTL_SB_NONE;
1415}
1416
1417/**
1418 * Change a P2P Role.
1419 * Parameters:
1420 * @mac: MAC address of the BSS to change a role
1421 * Returns 0 if success.
1422 */
1423int brcmf_p2p_ifchange(struct brcmf_cfg80211_info *cfg,
1424 enum brcmf_fil_p2p_if_types if_type)
1425{
1426 struct brcmf_p2p_info *p2p = &cfg->p2p;
1427 struct brcmf_cfg80211_vif *vif;
1428 struct brcmf_fil_p2p_if_le if_request;
1429 s32 err;
1430 u16 chanspec;
1431
1432 brcmf_dbg(TRACE, "Enter\n");
1433
1434 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
1435 if (!vif) {
1436 brcmf_err("vif for P2PAPI_BSSCFG_PRIMARY does not exist\n");
1437 return -EPERM;
1438 }
1439 brcmf_notify_escan_complete(cfg, vif->ifp->ndev, true, true);
1440 vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
1441 if (!vif) {
1442 brcmf_err("vif for P2PAPI_BSSCFG_CONNECTION does not exist\n");
1443 return -EPERM;
1444 }
1445 brcmf_set_mpc(vif->ifp->ndev, 0);
1446
1447 /* In concurrency case, STA may be already associated in a particular */
1448 /* channel. so retrieve the current channel of primary interface and */
1449 /* then start the virtual interface on that. */
1450 brcmf_p2p_get_current_chanspec(p2p, &chanspec);
1451
1452 if_request.type = cpu_to_le16((u16)if_type);
1453 if_request.chspec = cpu_to_le16(chanspec);
1454 memcpy(if_request.addr, p2p->int_addr, sizeof(if_request.addr));
1455
1456 brcmf_cfg80211_arm_vif_event(cfg, vif);
1457 err = brcmf_fil_iovar_data_set(vif->ifp, "p2p_ifupd", &if_request,
1458 sizeof(if_request));
1459 if (err) {
1460 brcmf_err("p2p_ifupd FAILED, err=%d\n", err);
1461 brcmf_cfg80211_arm_vif_event(cfg, NULL);
1462 return err;
1463 }
1464 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_CHANGE,
1465 msecs_to_jiffies(1500));
1466 brcmf_cfg80211_arm_vif_event(cfg, NULL);
1467 if (!err) {
1468 brcmf_err("No BRCMF_E_IF_CHANGE event received\n");
1469 return -EIO;
1470 }
1471
1472 err = brcmf_fil_cmd_int_set(vif->ifp, BRCMF_C_SET_SCB_TIMEOUT,
1473 BRCMF_SCB_TIMEOUT_VALUE);
1474
1475 return err;
1476}
1477
1478static int brcmf_p2p_request_p2p_if(struct brcmf_p2p_info *p2p,
1479 struct brcmf_if *ifp, u8 ea[ETH_ALEN],
Arend van Sprield3c0b632013-02-08 15:53:37 +01001480 enum brcmf_fil_p2p_if_types iftype)
1481{
1482 struct brcmf_fil_p2p_if_le if_request;
Arend van Sprield3c0b632013-02-08 15:53:37 +01001483 int err;
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01001484 u16 chanspec;
Arend van Sprield3c0b632013-02-08 15:53:37 +01001485
1486 /* we need a default channel */
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01001487 brcmf_p2p_get_current_chanspec(p2p, &chanspec);
Arend van Sprield3c0b632013-02-08 15:53:37 +01001488
1489 /* fill the firmware request */
1490 memcpy(if_request.addr, ea, ETH_ALEN);
Hante Meuleman7ee2d922013-02-08 15:53:43 +01001491 if_request.type = cpu_to_le16((u16)iftype);
Arend van Sprield3c0b632013-02-08 15:53:37 +01001492 if_request.chspec = cpu_to_le16(chanspec);
1493
1494 err = brcmf_fil_iovar_data_set(ifp, "p2p_ifadd", &if_request,
1495 sizeof(if_request));
1496 if (err)
1497 return err;
1498
Arend van Sprield3c0b632013-02-08 15:53:37 +01001499 return err;
1500}
1501
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01001502static int brcmf_p2p_disable_p2p_if(struct brcmf_cfg80211_vif *vif)
1503{
1504 struct brcmf_cfg80211_info *cfg = wdev_to_cfg(&vif->wdev);
1505 struct net_device *pri_ndev = cfg_to_ndev(cfg);
1506 struct brcmf_if *ifp = netdev_priv(pri_ndev);
1507 u8 *addr = vif->wdev.netdev->dev_addr;
1508
1509 return brcmf_fil_iovar_data_set(ifp, "p2p_ifdis", addr, ETH_ALEN);
1510}
1511
1512static int brcmf_p2p_release_p2p_if(struct brcmf_cfg80211_vif *vif)
1513{
1514 struct brcmf_cfg80211_info *cfg = wdev_to_cfg(&vif->wdev);
1515 struct net_device *pri_ndev = cfg_to_ndev(cfg);
1516 struct brcmf_if *ifp = netdev_priv(pri_ndev);
1517 u8 *addr = vif->wdev.netdev->dev_addr;
1518
1519 return brcmf_fil_iovar_data_set(ifp, "p2p_ifdel", addr, ETH_ALEN);
1520}
1521
Arend van Spriel9f440b72013-02-08 15:53:36 +01001522/**
1523 * brcmf_p2p_add_vif() - create a new P2P virtual interface.
1524 *
1525 * @wiphy: wiphy device of new interface.
1526 * @name: name of the new interface.
1527 * @type: nl80211 interface type.
1528 * @flags: TBD
1529 * @params: TBD
Arend van Spriel9f440b72013-02-08 15:53:36 +01001530 */
1531struct wireless_dev *brcmf_p2p_add_vif(struct wiphy *wiphy, const char *name,
1532 enum nl80211_iftype type, u32 *flags,
1533 struct vif_params *params)
1534{
Arend van Sprield3c0b632013-02-08 15:53:37 +01001535 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1536 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
1537 struct brcmf_cfg80211_vif *vif;
1538 enum brcmf_fil_p2p_if_types iftype;
1539 enum wl_mode mode;
1540 int err;
1541
1542 if (brcmf_cfg80211_vif_event_armed(cfg))
1543 return ERR_PTR(-EBUSY);
1544
Arend van Spriel9f440b72013-02-08 15:53:36 +01001545 brcmf_dbg(INFO, "adding vif \"%s\" (type=%d)\n", name, type);
Arend van Sprield3c0b632013-02-08 15:53:37 +01001546
1547 switch (type) {
1548 case NL80211_IFTYPE_P2P_CLIENT:
1549 iftype = BRCMF_FIL_P2P_IF_CLIENT;
1550 mode = WL_MODE_BSS;
1551 break;
1552 case NL80211_IFTYPE_P2P_GO:
1553 iftype = BRCMF_FIL_P2P_IF_GO;
1554 mode = WL_MODE_AP;
1555 break;
1556 default:
1557 return ERR_PTR(-EOPNOTSUPP);
1558 }
1559
1560 vif = brcmf_alloc_vif(cfg, type, false);
Hante Meuleman7ee2d922013-02-08 15:53:43 +01001561 if (IS_ERR(vif))
1562 return (struct wireless_dev *)vif;
Arend van Sprield3c0b632013-02-08 15:53:37 +01001563 brcmf_cfg80211_arm_vif_event(cfg, vif);
1564
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01001565 err = brcmf_p2p_request_p2p_if(&cfg->p2p, ifp, cfg->p2p.int_addr,
1566 iftype);
Hante Meuleman7ee2d922013-02-08 15:53:43 +01001567 if (err) {
1568 brcmf_cfg80211_arm_vif_event(cfg, NULL);
Arend van Sprield3c0b632013-02-08 15:53:37 +01001569 goto fail;
Hante Meuleman7ee2d922013-02-08 15:53:43 +01001570 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01001571
1572 /* wait for firmware event */
1573 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_ADD,
1574 msecs_to_jiffies(1500));
1575 brcmf_cfg80211_arm_vif_event(cfg, NULL);
1576 if (!err) {
1577 brcmf_err("timeout occurred\n");
1578 err = -EIO;
1579 goto fail;
1580 }
1581
1582 /* interface created in firmware */
1583 ifp = vif->ifp;
1584 if (!ifp) {
1585 brcmf_err("no if pointer provided\n");
1586 err = -ENOENT;
Hante Meuleman7ee2d922013-02-08 15:53:43 +01001587 goto fail;
Arend van Sprield3c0b632013-02-08 15:53:37 +01001588 }
1589
1590 strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1);
1591 brcmf_cfg80211_vif_complete(cfg);
Hante Meuleman7ee2d922013-02-08 15:53:43 +01001592 cfg->p2p.bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = vif;
1593 /* Disable firmware roaming for P2P interface */
1594 brcmf_fil_iovar_int_set(ifp, "roam_off", 1);
1595 if (iftype == BRCMF_FIL_P2P_IF_GO) {
1596 /* set station timeout for p2p */
1597 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCB_TIMEOUT,
1598 BRCMF_SCB_TIMEOUT_VALUE);
1599 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01001600 return &ifp->vif->wdev;
1601
1602fail:
1603 brcmf_free_vif(vif);
1604 return ERR_PTR(err);
Arend van Spriel9f440b72013-02-08 15:53:36 +01001605}
1606
1607/**
1608 * brcmf_p2p_del_vif() - delete a P2P virtual interface.
1609 *
1610 * @wiphy: wiphy device of interface.
1611 * @wdev: wireless device of interface.
1612 *
1613 * TODO: not yet supported.
1614 */
1615int brcmf_p2p_del_vif(struct wiphy *wiphy, struct wireless_dev *wdev)
1616{
Arend van Sprield3c0b632013-02-08 15:53:37 +01001617 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Arend van Spriel9f440b72013-02-08 15:53:36 +01001618 struct brcmf_cfg80211_vif *vif;
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01001619 unsigned long jiffie_timeout = msecs_to_jiffies(1500);
1620 bool wait_for_disable = false;
Arend van Sprield3c0b632013-02-08 15:53:37 +01001621 int err;
Arend van Spriel9f440b72013-02-08 15:53:36 +01001622
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01001623 brcmf_dbg(TRACE, "delete P2P vif\n");
Arend van Spriel9f440b72013-02-08 15:53:36 +01001624 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
Arend van Sprield3c0b632013-02-08 15:53:37 +01001625
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01001626 switch (vif->wdev.iftype) {
1627 case NL80211_IFTYPE_P2P_CLIENT:
1628 if (test_bit(BRCMF_VIF_STATUS_DISCONNECTING, &vif->sme_state))
1629 wait_for_disable = true;
1630 break;
1631
1632 case NL80211_IFTYPE_P2P_GO:
1633 if (!brcmf_p2p_disable_p2p_if(vif))
1634 wait_for_disable = true;
1635 break;
1636
1637 case NL80211_IFTYPE_P2P_DEVICE:
1638 default:
1639 return -ENOTSUPP;
1640 break;
1641 }
1642
1643 if (wait_for_disable)
Hante Meuleman7ee2d922013-02-08 15:53:43 +01001644 wait_for_completion_timeout(&cfg->vif_disabled,
1645 msecs_to_jiffies(500));
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01001646
1647 brcmf_vif_clear_mgmt_ies(vif);
Arend van Sprield3c0b632013-02-08 15:53:37 +01001648
1649 brcmf_cfg80211_arm_vif_event(cfg, vif);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01001650 err = brcmf_p2p_release_p2p_if(vif);
Hante Meuleman7ee2d922013-02-08 15:53:43 +01001651 if (!err) {
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01001652 /* wait for firmware event */
1653 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_DEL,
1654 jiffie_timeout);
Hante Meuleman7ee2d922013-02-08 15:53:43 +01001655 if (!err)
1656 err = -EIO;
1657 else
1658 err = 0;
1659 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01001660 brcmf_cfg80211_arm_vif_event(cfg, NULL);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01001661 brcmf_free_vif(vif);
Hante Meuleman7ee2d922013-02-08 15:53:43 +01001662 cfg->p2p.bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = NULL;
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01001663
1664 return err;
Arend van Spriel9f440b72013-02-08 15:53:36 +01001665}