blob: a5902c383bac773e659072078d57d11ccfc17fe1 [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>
Arend van Spriel27f10e32013-04-05 10:57:50 +020018#include <linux/etherdevice.h>
Arend van Sprielf7a40872015-06-11 00:12:23 +020019#include <linux/rtnetlink.h>
Arend van Spriel9f440b72013-02-08 15:53:36 +010020#include <net/cfg80211.h>
21
22#include <brcmu_wifi.h>
23#include <brcmu_utils.h>
24#include <defs.h>
Hante Meuleman122d3d02014-10-28 14:56:18 +010025#include "core.h"
Hante Meulemana8e8ed32014-10-28 14:56:13 +010026#include "debug.h"
Arend van Spriel9f440b72013-02-08 15:53:36 +010027#include "fwil.h"
Arend van Sprield3c0b632013-02-08 15:53:37 +010028#include "fwil_types.h"
Arend van Spriel9f440b72013-02-08 15:53:36 +010029#include "p2p.h"
Hante Meulemanbfe81972014-10-28 14:56:16 +010030#include "cfg80211.h"
Arend van Spriel9f440b72013-02-08 15:53:36 +010031
32/* parameters used for p2p escan */
33#define P2PAPI_SCAN_NPROBES 1
34#define P2PAPI_SCAN_DWELL_TIME_MS 80
35#define P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS 40
36#define P2PAPI_SCAN_HOME_TIME_MS 60
37#define P2PAPI_SCAN_NPROBS_TIME_MS 30
38#define P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS 100
39#define WL_SCAN_CONNECT_DWELL_TIME_MS 200
40#define WL_SCAN_JOIN_PROBE_INTERVAL_MS 20
41
42#define BRCMF_P2P_WILDCARD_SSID "DIRECT-"
43#define BRCMF_P2P_WILDCARD_SSID_LEN (sizeof(BRCMF_P2P_WILDCARD_SSID) - 1)
44
45#define SOCIAL_CHAN_1 1
46#define SOCIAL_CHAN_2 6
47#define SOCIAL_CHAN_3 11
Hante Meuleman6eda4e22013-02-08 15:54:02 +010048#define IS_P2P_SOCIAL_CHANNEL(channel) ((channel == SOCIAL_CHAN_1) || \
49 (channel == SOCIAL_CHAN_2) || \
50 (channel == SOCIAL_CHAN_3))
Hante Meuleman15a953d2013-05-27 21:09:54 +020051#define BRCMF_P2P_TEMP_CHAN SOCIAL_CHAN_3
Arend van Spriel9f440b72013-02-08 15:53:36 +010052#define SOCIAL_CHAN_CNT 3
53#define AF_PEER_SEARCH_CNT 2
54
Arend van Sprield3c0b632013-02-08 15:53:37 +010055#define BRCMF_SCB_TIMEOUT_VALUE 20
56
Hante Meulemane6da3402013-02-08 15:53:48 +010057#define P2P_VER 9 /* P2P version: 9=WiFi P2P v1.0 */
58#define P2P_PUB_AF_CATEGORY 0x04
59#define P2P_PUB_AF_ACTION 0x09
60#define P2P_AF_CATEGORY 0x7f
61#define P2P_OUI "\x50\x6F\x9A" /* P2P OUI */
62#define P2P_OUI_LEN 3 /* P2P OUI length */
63
Hante Meuleman18e2f612013-02-08 15:53:49 +010064/* Action Frame Constants */
65#define DOT11_ACTION_HDR_LEN 2 /* action frame category + action */
66#define DOT11_ACTION_CAT_OFF 0 /* category offset */
67#define DOT11_ACTION_ACT_OFF 1 /* action offset */
68
69#define P2P_AF_DWELL_TIME 200
70#define P2P_AF_MIN_DWELL_TIME 100
71#define P2P_AF_MED_DWELL_TIME 400
72#define P2P_AF_LONG_DWELL_TIME 1000
Hante Meuleman6eda4e22013-02-08 15:54:02 +010073#define P2P_AF_TX_MAX_RETRY 1
Hante Meuleman18e2f612013-02-08 15:53:49 +010074#define P2P_AF_MAX_WAIT_TIME 2000
75#define P2P_INVALID_CHANNEL -1
76#define P2P_CHANNEL_SYNC_RETRY 5
77#define P2P_AF_FRM_SCAN_MAX_WAIT 1500
Hante Meuleman6eda4e22013-02-08 15:54:02 +010078#define P2P_DEFAULT_SLEEP_TIME_VSDB 200
Hante Meuleman18e2f612013-02-08 15:53:49 +010079
Hante Meulemane6da3402013-02-08 15:53:48 +010080/* WiFi P2P Public Action Frame OUI Subtypes */
81#define P2P_PAF_GON_REQ 0 /* Group Owner Negotiation Req */
82#define P2P_PAF_GON_RSP 1 /* Group Owner Negotiation Rsp */
83#define P2P_PAF_GON_CONF 2 /* Group Owner Negotiation Confirm */
84#define P2P_PAF_INVITE_REQ 3 /* P2P Invitation Request */
85#define P2P_PAF_INVITE_RSP 4 /* P2P Invitation Response */
86#define P2P_PAF_DEVDIS_REQ 5 /* Device Discoverability Request */
87#define P2P_PAF_DEVDIS_RSP 6 /* Device Discoverability Response */
88#define P2P_PAF_PROVDIS_REQ 7 /* Provision Discovery Request */
89#define P2P_PAF_PROVDIS_RSP 8 /* Provision Discovery Response */
90#define P2P_PAF_SUBTYPE_INVALID 255 /* Invalid Subtype */
91
92/* WiFi P2P Action Frame OUI Subtypes */
93#define P2P_AF_NOTICE_OF_ABSENCE 0 /* Notice of Absence */
94#define P2P_AF_PRESENCE_REQ 1 /* P2P Presence Request */
95#define P2P_AF_PRESENCE_RSP 2 /* P2P Presence Response */
96#define P2P_AF_GO_DISC_REQ 3 /* GO Discoverability Request */
97
98/* P2P Service Discovery related */
99#define P2PSD_ACTION_CATEGORY 0x04 /* Public action frame */
100#define P2PSD_ACTION_ID_GAS_IREQ 0x0a /* GAS Initial Request AF */
101#define P2PSD_ACTION_ID_GAS_IRESP 0x0b /* GAS Initial Response AF */
102#define P2PSD_ACTION_ID_GAS_CREQ 0x0c /* GAS Comback Request AF */
103#define P2PSD_ACTION_ID_GAS_CRESP 0x0d /* GAS Comback Response AF */
104
Arend van Spriel9f440b72013-02-08 15:53:36 +0100105/**
106 * struct brcmf_p2p_disc_st_le - set discovery state in firmware.
107 *
108 * @state: requested discovery state (see enum brcmf_p2p_disc_state).
109 * @chspec: channel parameter for %WL_P2P_DISC_ST_LISTEN state.
110 * @dwell: dwell time in ms for %WL_P2P_DISC_ST_LISTEN state.
111 */
112struct brcmf_p2p_disc_st_le {
113 u8 state;
114 __le16 chspec;
115 __le16 dwell;
116};
117
118/**
119 * enum brcmf_p2p_disc_state - P2P discovery state values
120 *
121 * @WL_P2P_DISC_ST_SCAN: P2P discovery with wildcard SSID and P2P IE.
122 * @WL_P2P_DISC_ST_LISTEN: P2P discovery off-channel for specified time.
123 * @WL_P2P_DISC_ST_SEARCH: P2P discovery with P2P wildcard SSID and P2P IE.
124 */
125enum brcmf_p2p_disc_state {
126 WL_P2P_DISC_ST_SCAN,
127 WL_P2P_DISC_ST_LISTEN,
128 WL_P2P_DISC_ST_SEARCH
129};
130
131/**
132 * struct brcmf_p2p_scan_le - P2P specific scan request.
133 *
134 * @type: type of scan method requested (values: 'E' or 'S').
135 * @reserved: reserved (ignored).
136 * @eparams: parameters used for type 'E'.
137 * @sparams: parameters used for type 'S'.
138 */
139struct brcmf_p2p_scan_le {
140 u8 type;
141 u8 reserved[3];
142 union {
143 struct brcmf_escan_params_le eparams;
144 struct brcmf_scan_params_le sparams;
145 };
146};
147
Arend van Spriel9f440b72013-02-08 15:53:36 +0100148/**
Hante Meulemane6da3402013-02-08 15:53:48 +0100149 * struct brcmf_p2p_pub_act_frame - WiFi P2P Public Action Frame
150 *
151 * @category: P2P_PUB_AF_CATEGORY
152 * @action: P2P_PUB_AF_ACTION
153 * @oui[3]: P2P_OUI
154 * @oui_type: OUI type - P2P_VER
155 * @subtype: OUI subtype - P2P_TYPE_*
156 * @dialog_token: nonzero, identifies req/rsp transaction
157 * @elts[1]: Variable length information elements.
158 */
159struct brcmf_p2p_pub_act_frame {
160 u8 category;
161 u8 action;
162 u8 oui[3];
163 u8 oui_type;
164 u8 subtype;
165 u8 dialog_token;
166 u8 elts[1];
167};
168
169/**
170 * struct brcmf_p2p_action_frame - WiFi P2P Action Frame
171 *
172 * @category: P2P_AF_CATEGORY
173 * @OUI[3]: OUI - P2P_OUI
174 * @type: OUI Type - P2P_VER
175 * @subtype: OUI Subtype - P2P_AF_*
176 * @dialog_token: nonzero, identifies req/resp tranaction
177 * @elts[1]: Variable length information elements.
178 */
179struct brcmf_p2p_action_frame {
180 u8 category;
181 u8 oui[3];
182 u8 type;
183 u8 subtype;
184 u8 dialog_token;
185 u8 elts[1];
186};
187
188/**
189 * struct brcmf_p2psd_gas_pub_act_frame - Wi-Fi GAS Public Action Frame
190 *
191 * @category: 0x04 Public Action Frame
192 * @action: 0x6c Advertisement Protocol
193 * @dialog_token: nonzero, identifies req/rsp transaction
194 * @query_data[1]: Query Data. SD gas ireq SD gas iresp
195 */
196struct brcmf_p2psd_gas_pub_act_frame {
197 u8 category;
198 u8 action;
199 u8 dialog_token;
200 u8 query_data[1];
201};
202
Hante Meuleman18e2f612013-02-08 15:53:49 +0100203/**
204 * struct brcmf_config_af_params - Action Frame Parameters for tx.
205 *
Hante Meuleman18e2f612013-02-08 15:53:49 +0100206 * @mpc_onoff: To make sure to send successfully action frame, we have to
207 * turn off mpc 0: off, 1: on, (-1): do nothing
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100208 * @search_channel: 1: search peer's channel to send af
209 * extra_listen: keep the dwell time to get af response frame.
Hante Meuleman18e2f612013-02-08 15:53:49 +0100210 */
211struct brcmf_config_af_params {
Hante Meuleman18e2f612013-02-08 15:53:49 +0100212 s32 mpc_onoff;
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100213 bool search_channel;
214 bool extra_listen;
Hante Meuleman18e2f612013-02-08 15:53:49 +0100215};
Hante Meulemane6da3402013-02-08 15:53:48 +0100216
217/**
218 * brcmf_p2p_is_pub_action() - true if p2p public type frame.
219 *
220 * @frame: action frame data.
221 * @frame_len: length of action frame data.
222 *
223 * Determine if action frame is p2p public action type
224 */
225static bool brcmf_p2p_is_pub_action(void *frame, u32 frame_len)
226{
227 struct brcmf_p2p_pub_act_frame *pact_frm;
228
229 if (frame == NULL)
230 return false;
231
232 pact_frm = (struct brcmf_p2p_pub_act_frame *)frame;
233 if (frame_len < sizeof(struct brcmf_p2p_pub_act_frame) - 1)
234 return false;
235
236 if (pact_frm->category == P2P_PUB_AF_CATEGORY &&
237 pact_frm->action == P2P_PUB_AF_ACTION &&
238 pact_frm->oui_type == P2P_VER &&
239 memcmp(pact_frm->oui, P2P_OUI, P2P_OUI_LEN) == 0)
240 return true;
241
242 return false;
243}
244
245/**
246 * brcmf_p2p_is_p2p_action() - true if p2p action type frame.
247 *
248 * @frame: action frame data.
249 * @frame_len: length of action frame data.
250 *
251 * Determine if action frame is p2p action type
252 */
253static bool brcmf_p2p_is_p2p_action(void *frame, u32 frame_len)
254{
255 struct brcmf_p2p_action_frame *act_frm;
256
257 if (frame == NULL)
258 return false;
259
260 act_frm = (struct brcmf_p2p_action_frame *)frame;
261 if (frame_len < sizeof(struct brcmf_p2p_action_frame) - 1)
262 return false;
263
264 if (act_frm->category == P2P_AF_CATEGORY &&
265 act_frm->type == P2P_VER &&
266 memcmp(act_frm->oui, P2P_OUI, P2P_OUI_LEN) == 0)
267 return true;
268
269 return false;
270}
271
272/**
273 * brcmf_p2p_is_gas_action() - true if p2p gas action type frame.
274 *
275 * @frame: action frame data.
276 * @frame_len: length of action frame data.
277 *
278 * Determine if action frame is p2p gas action type
279 */
280static bool brcmf_p2p_is_gas_action(void *frame, u32 frame_len)
281{
282 struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm;
283
284 if (frame == NULL)
285 return false;
286
287 sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame;
288 if (frame_len < sizeof(struct brcmf_p2psd_gas_pub_act_frame) - 1)
289 return false;
290
291 if (sd_act_frm->category != P2PSD_ACTION_CATEGORY)
292 return false;
293
294 if (sd_act_frm->action == P2PSD_ACTION_ID_GAS_IREQ ||
295 sd_act_frm->action == P2PSD_ACTION_ID_GAS_IRESP ||
296 sd_act_frm->action == P2PSD_ACTION_ID_GAS_CREQ ||
297 sd_act_frm->action == P2PSD_ACTION_ID_GAS_CRESP)
298 return true;
299
300 return false;
301}
302
303/**
304 * brcmf_p2p_print_actframe() - debug print routine.
305 *
306 * @tx: Received or to be transmitted
307 * @frame: action frame data.
308 * @frame_len: length of action frame data.
309 *
310 * Print information about the p2p action frame
311 */
Hante Meuleman0a4cf482013-02-08 15:53:54 +0100312
313#ifdef DEBUG
314
Hante Meulemane6da3402013-02-08 15:53:48 +0100315static void brcmf_p2p_print_actframe(bool tx, void *frame, u32 frame_len)
316{
317 struct brcmf_p2p_pub_act_frame *pact_frm;
318 struct brcmf_p2p_action_frame *act_frm;
319 struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm;
320
321 if (!frame || frame_len <= 2)
322 return;
323
324 if (brcmf_p2p_is_pub_action(frame, frame_len)) {
325 pact_frm = (struct brcmf_p2p_pub_act_frame *)frame;
326 switch (pact_frm->subtype) {
327 case P2P_PAF_GON_REQ:
328 brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Req Frame\n",
329 (tx) ? "TX" : "RX");
330 break;
331 case P2P_PAF_GON_RSP:
332 brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Rsp Frame\n",
333 (tx) ? "TX" : "RX");
334 break;
335 case P2P_PAF_GON_CONF:
336 brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Confirm Frame\n",
337 (tx) ? "TX" : "RX");
338 break;
339 case P2P_PAF_INVITE_REQ:
340 brcmf_dbg(TRACE, "%s P2P Invitation Request Frame\n",
341 (tx) ? "TX" : "RX");
342 break;
343 case P2P_PAF_INVITE_RSP:
344 brcmf_dbg(TRACE, "%s P2P Invitation Response Frame\n",
345 (tx) ? "TX" : "RX");
346 break;
347 case P2P_PAF_DEVDIS_REQ:
348 brcmf_dbg(TRACE, "%s P2P Device Discoverability Request Frame\n",
349 (tx) ? "TX" : "RX");
350 break;
351 case P2P_PAF_DEVDIS_RSP:
352 brcmf_dbg(TRACE, "%s P2P Device Discoverability Response Frame\n",
353 (tx) ? "TX" : "RX");
354 break;
355 case P2P_PAF_PROVDIS_REQ:
356 brcmf_dbg(TRACE, "%s P2P Provision Discovery Request Frame\n",
357 (tx) ? "TX" : "RX");
358 break;
359 case P2P_PAF_PROVDIS_RSP:
360 brcmf_dbg(TRACE, "%s P2P Provision Discovery Response Frame\n",
361 (tx) ? "TX" : "RX");
362 break;
363 default:
364 brcmf_dbg(TRACE, "%s Unknown P2P Public Action Frame\n",
365 (tx) ? "TX" : "RX");
366 break;
367 }
368 } else if (brcmf_p2p_is_p2p_action(frame, frame_len)) {
369 act_frm = (struct brcmf_p2p_action_frame *)frame;
370 switch (act_frm->subtype) {
371 case P2P_AF_NOTICE_OF_ABSENCE:
372 brcmf_dbg(TRACE, "%s P2P Notice of Absence Frame\n",
373 (tx) ? "TX" : "RX");
374 break;
375 case P2P_AF_PRESENCE_REQ:
376 brcmf_dbg(TRACE, "%s P2P Presence Request Frame\n",
377 (tx) ? "TX" : "RX");
378 break;
379 case P2P_AF_PRESENCE_RSP:
380 brcmf_dbg(TRACE, "%s P2P Presence Response Frame\n",
381 (tx) ? "TX" : "RX");
382 break;
383 case P2P_AF_GO_DISC_REQ:
384 brcmf_dbg(TRACE, "%s P2P Discoverability Request Frame\n",
385 (tx) ? "TX" : "RX");
386 break;
387 default:
388 brcmf_dbg(TRACE, "%s Unknown P2P Action Frame\n",
389 (tx) ? "TX" : "RX");
390 }
391
392 } else if (brcmf_p2p_is_gas_action(frame, frame_len)) {
393 sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame;
394 switch (sd_act_frm->action) {
395 case P2PSD_ACTION_ID_GAS_IREQ:
396 brcmf_dbg(TRACE, "%s P2P GAS Initial Request\n",
397 (tx) ? "TX" : "RX");
398 break;
399 case P2PSD_ACTION_ID_GAS_IRESP:
400 brcmf_dbg(TRACE, "%s P2P GAS Initial Response\n",
401 (tx) ? "TX" : "RX");
402 break;
403 case P2PSD_ACTION_ID_GAS_CREQ:
404 brcmf_dbg(TRACE, "%s P2P GAS Comback Request\n",
405 (tx) ? "TX" : "RX");
406 break;
407 case P2PSD_ACTION_ID_GAS_CRESP:
408 brcmf_dbg(TRACE, "%s P2P GAS Comback Response\n",
409 (tx) ? "TX" : "RX");
410 break;
411 default:
412 brcmf_dbg(TRACE, "%s Unknown P2P GAS Frame\n",
413 (tx) ? "TX" : "RX");
414 break;
415 }
416 }
417}
418
Hante Meuleman0a4cf482013-02-08 15:53:54 +0100419#else
420
421static void brcmf_p2p_print_actframe(bool tx, void *frame, u32 frame_len)
422{
423}
424
425#endif
426
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100427
428/**
Arend van Spriel9f440b72013-02-08 15:53:36 +0100429 * brcmf_p2p_set_firmware() - prepare firmware for peer-to-peer operation.
430 *
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100431 * @ifp: ifp to use for iovars (primary).
432 * @p2p_mac: mac address to configure for p2p_da_override
Arend van Spriel9f440b72013-02-08 15:53:36 +0100433 */
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100434static int brcmf_p2p_set_firmware(struct brcmf_if *ifp, u8 *p2p_mac)
Arend van Spriel9f440b72013-02-08 15:53:36 +0100435{
Arend van Spriel9f440b72013-02-08 15:53:36 +0100436 s32 ret = 0;
437
Arend van Spriel27f10e32013-04-05 10:57:50 +0200438 brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100439 brcmf_fil_iovar_int_set(ifp, "apsta", 1);
Arend van Spriel27f10e32013-04-05 10:57:50 +0200440 brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100441
442 /* In case of COB type, firmware has default mac address
443 * After Initializing firmware, we have to set current mac address to
Arend van Sprielf48556e2014-09-30 10:23:16 +0200444 * firmware for P2P device address. This must be done with discovery
445 * disabled.
Arend van Spriel9f440b72013-02-08 15:53:36 +0100446 */
Arend van Sprielf48556e2014-09-30 10:23:16 +0200447 brcmf_fil_iovar_int_set(ifp, "p2p_disc", 0);
448
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100449 ret = brcmf_fil_iovar_data_set(ifp, "p2p_da_override", p2p_mac,
450 ETH_ALEN);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100451 if (ret)
452 brcmf_err("failed to update device address ret %d\n", ret);
453
454 return ret;
455}
456
457/**
458 * brcmf_p2p_generate_bss_mac() - derive mac addresses for P2P.
459 *
460 * @p2p: P2P specific data.
Arend van Spriel27f10e32013-04-05 10:57:50 +0200461 * @dev_addr: optional device address.
Arend van Spriel9f440b72013-02-08 15:53:36 +0100462 *
Arend van Spriel27f10e32013-04-05 10:57:50 +0200463 * P2P needs mac addresses for P2P device and interface. If no device
464 * address it specified, these are derived from the primary net device, ie.
465 * the permanent ethernet address of the device.
Arend van Spriel9f440b72013-02-08 15:53:36 +0100466 */
Arend van Spriel27f10e32013-04-05 10:57:50 +0200467static void brcmf_p2p_generate_bss_mac(struct brcmf_p2p_info *p2p, u8 *dev_addr)
Arend van Spriel9f440b72013-02-08 15:53:36 +0100468{
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100469 struct brcmf_if *pri_ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
Arend van Spriel27f10e32013-04-05 10:57:50 +0200470 bool local_admin = false;
471
472 if (!dev_addr || is_zero_ether_addr(dev_addr)) {
473 dev_addr = pri_ifp->mac_addr;
474 local_admin = true;
475 }
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100476
Arend van Spriel9f440b72013-02-08 15:53:36 +0100477 /* Generate the P2P Device Address. This consists of the device's
478 * primary MAC address with the locally administered bit set.
479 */
Arend van Spriel27f10e32013-04-05 10:57:50 +0200480 memcpy(p2p->dev_addr, dev_addr, ETH_ALEN);
481 if (local_admin)
482 p2p->dev_addr[0] |= 0x02;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100483
484 /* Generate the P2P Interface Address. If the discovery and connection
485 * BSSCFGs need to simultaneously co-exist, then this address must be
486 * different from the P2P Device Address, but also locally administered.
487 */
488 memcpy(p2p->int_addr, p2p->dev_addr, ETH_ALEN);
Arend van Spriel27f10e32013-04-05 10:57:50 +0200489 p2p->int_addr[0] |= 0x02;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100490 p2p->int_addr[4] ^= 0x80;
491}
492
493/**
494 * brcmf_p2p_scan_is_p2p_request() - is cfg80211 scan request a P2P scan.
495 *
496 * @request: the scan request as received from cfg80211.
497 *
498 * returns true if one of the ssids in the request matches the
499 * P2P wildcard ssid; otherwise returns false.
500 */
501static bool brcmf_p2p_scan_is_p2p_request(struct cfg80211_scan_request *request)
502{
503 struct cfg80211_ssid *ssids = request->ssids;
504 int i;
505
506 for (i = 0; i < request->n_ssids; i++) {
507 if (ssids[i].ssid_len != BRCMF_P2P_WILDCARD_SSID_LEN)
508 continue;
509
510 brcmf_dbg(INFO, "comparing ssid \"%s\"", ssids[i].ssid);
511 if (!memcmp(BRCMF_P2P_WILDCARD_SSID, ssids[i].ssid,
512 BRCMF_P2P_WILDCARD_SSID_LEN))
513 return true;
514 }
515 return false;
516}
517
518/**
519 * brcmf_p2p_set_discover_state - set discover state in firmware.
520 *
521 * @ifp: low-level interface object.
522 * @state: discover state to set.
523 * @chanspec: channel parameters (for state @WL_P2P_DISC_ST_LISTEN only).
524 * @listen_ms: duration to listen (for state @WL_P2P_DISC_ST_LISTEN only).
525 */
526static s32 brcmf_p2p_set_discover_state(struct brcmf_if *ifp, u8 state,
527 u16 chanspec, u16 listen_ms)
528{
529 struct brcmf_p2p_disc_st_le discover_state;
530 s32 ret = 0;
531 brcmf_dbg(TRACE, "enter\n");
532
533 discover_state.state = state;
534 discover_state.chspec = cpu_to_le16(chanspec);
535 discover_state.dwell = cpu_to_le16(listen_ms);
536 ret = brcmf_fil_bsscfg_data_set(ifp, "p2p_state", &discover_state,
537 sizeof(discover_state));
538 return ret;
539}
540
541/**
Arend van Spriel9f440b72013-02-08 15:53:36 +0100542 * brcmf_p2p_deinit_discovery() - disable P2P device discovery.
543 *
544 * @p2p: P2P specific data.
545 *
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100546 * Resets the discovery state and disables it in firmware.
Arend van Spriel9f440b72013-02-08 15:53:36 +0100547 */
548static s32 brcmf_p2p_deinit_discovery(struct brcmf_p2p_info *p2p)
549{
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100550 struct brcmf_cfg80211_vif *vif;
551
Arend van Spriel9f440b72013-02-08 15:53:36 +0100552 brcmf_dbg(TRACE, "enter\n");
553
Arend van Spriel9f440b72013-02-08 15:53:36 +0100554 /* Set the discovery state to SCAN */
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100555 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
556 (void)brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100557
558 /* Disable P2P discovery in the firmware */
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100559 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
560 (void)brcmf_fil_iovar_int_set(vif->ifp, "p2p_disc", 0);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100561
562 return 0;
563}
564
565/**
566 * brcmf_p2p_enable_discovery() - initialize and configure discovery.
567 *
568 * @p2p: P2P specific data.
Arend van Spriel9f440b72013-02-08 15:53:36 +0100569 *
570 * Initializes the discovery device and configure the virtual interface.
571 */
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100572static int brcmf_p2p_enable_discovery(struct brcmf_p2p_info *p2p)
Arend van Spriel9f440b72013-02-08 15:53:36 +0100573{
574 struct brcmf_cfg80211_vif *vif;
575 s32 ret = 0;
576
577 brcmf_dbg(TRACE, "enter\n");
578 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100579 if (!vif) {
580 brcmf_err("P2P config device not available\n");
581 ret = -EPERM;
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100582 goto exit;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100583 }
584
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100585 if (test_bit(BRCMF_P2P_STATUS_ENABLED, &p2p->status)) {
586 brcmf_dbg(INFO, "P2P config device already configured\n");
587 goto exit;
588 }
589
590 /* Re-initialize P2P Discovery in the firmware */
591 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
592 ret = brcmf_fil_iovar_int_set(vif->ifp, "p2p_disc", 1);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100593 if (ret < 0) {
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100594 brcmf_err("set p2p_disc error\n");
Arend van Spriel9f440b72013-02-08 15:53:36 +0100595 goto exit;
596 }
Arend van Spriel9f440b72013-02-08 15:53:36 +0100597 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100598 ret = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
599 if (ret < 0) {
600 brcmf_err("unable to set WL_P2P_DISC_ST_SCAN\n");
601 goto exit;
602 }
Arend van Spriel9f440b72013-02-08 15:53:36 +0100603
604 /*
605 * Set wsec to any non-zero value in the discovery bsscfg
606 * to ensure our P2P probe responses have the privacy bit
607 * set in the 802.11 WPA IE. Some peer devices may not
608 * initiate WPS with us if this bit is not set.
609 */
610 ret = brcmf_fil_bsscfg_int_set(vif->ifp, "wsec", AES_ENABLED);
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100611 if (ret < 0) {
Arend van Spriel9f440b72013-02-08 15:53:36 +0100612 brcmf_err("wsec error %d\n", ret);
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100613 goto exit;
614 }
Arend van Spriel9f440b72013-02-08 15:53:36 +0100615
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100616 set_bit(BRCMF_P2P_STATUS_ENABLED, &p2p->status);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100617exit:
618 return ret;
619}
620
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100621/**
Arend van Spriel9f440b72013-02-08 15:53:36 +0100622 * brcmf_p2p_escan() - initiate a P2P scan.
623 *
624 * @p2p: P2P specific data.
625 * @num_chans: number of channels to scan.
626 * @chanspecs: channel parameters for @num_chans channels.
627 * @search_state: P2P discover state to use.
628 * @action: scan action to pass to firmware.
629 * @bss_type: type of P2P bss.
630 */
631static s32 brcmf_p2p_escan(struct brcmf_p2p_info *p2p, u32 num_chans,
632 u16 chanspecs[], s32 search_state, u16 action,
633 enum p2p_bss_type bss_type)
634{
635 s32 ret = 0;
636 s32 memsize = offsetof(struct brcmf_p2p_scan_le,
637 eparams.params_le.channel_list);
638 s32 nprobes;
639 s32 active;
640 u32 i;
641 u8 *memblk;
642 struct brcmf_cfg80211_vif *vif;
643 struct brcmf_p2p_scan_le *p2p_params;
644 struct brcmf_scan_params_le *sparams;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100645
Arend van Spriel9f440b72013-02-08 15:53:36 +0100646 memsize += num_chans * sizeof(__le16);
647 memblk = kzalloc(memsize, GFP_KERNEL);
648 if (!memblk)
649 return -ENOMEM;
650
651 vif = p2p->bss_idx[bss_type].vif;
652 if (vif == NULL) {
653 brcmf_err("no vif for bss type %d\n", bss_type);
654 ret = -EINVAL;
655 goto exit;
656 }
Hante Meulemane9a6ca82015-11-25 11:32:37 +0100657 p2p_params = (struct brcmf_p2p_scan_le *)memblk;
658 sparams = &p2p_params->eparams.params_le;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100659
660 switch (search_state) {
661 case WL_P2P_DISC_ST_SEARCH:
662 /*
663 * If we in SEARCH STATE, we don't need to set SSID explictly
Hante Meulemane9a6ca82015-11-25 11:32:37 +0100664 * because dongle use P2P WILDCARD internally by default, use
665 * null ssid, which it is already due to kzalloc.
Arend van Spriel9f440b72013-02-08 15:53:36 +0100666 */
Arend van Spriel9f440b72013-02-08 15:53:36 +0100667 break;
668 case WL_P2P_DISC_ST_SCAN:
669 /*
670 * wpa_supplicant has p2p_find command with type social or
671 * progressive. For progressive, we need to set the ssid to
672 * P2P WILDCARD because we just do broadcast scan unless
673 * setting SSID.
674 */
Hante Meulemane9a6ca82015-11-25 11:32:37 +0100675 sparams->ssid_le.SSID_len =
676 cpu_to_le32(BRCMF_P2P_WILDCARD_SSID_LEN);
677 memcpy(sparams->ssid_le.SSID, BRCMF_P2P_WILDCARD_SSID,
678 BRCMF_P2P_WILDCARD_SSID_LEN);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100679 break;
680 default:
681 brcmf_err(" invalid search state %d\n", search_state);
682 ret = -EINVAL;
683 goto exit;
684 }
685
686 brcmf_p2p_set_discover_state(vif->ifp, search_state, 0, 0);
687
688 /*
689 * set p2p scan parameters.
690 */
Arend van Spriel9f440b72013-02-08 15:53:36 +0100691 p2p_params->type = 'E';
692
693 /* determine the scan engine parameters */
Arend van Spriel9f440b72013-02-08 15:53:36 +0100694 sparams->bss_type = DOT11_BSSTYPE_ANY;
695 if (p2p->cfg->active_scan)
696 sparams->scan_type = 0;
697 else
698 sparams->scan_type = 1;
699
Joe Perches93803b32015-03-02 19:54:49 -0800700 eth_broadcast_addr(sparams->bssid);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100701 sparams->home_time = cpu_to_le32(P2PAPI_SCAN_HOME_TIME_MS);
702
703 /*
704 * SOCIAL_CHAN_CNT + 1 takes care of the Progressive scan
705 * supported by the supplicant.
706 */
707 if (num_chans == SOCIAL_CHAN_CNT || num_chans == (SOCIAL_CHAN_CNT + 1))
708 active = P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS;
709 else if (num_chans == AF_PEER_SEARCH_CNT)
710 active = P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS;
Rasmus Villemoese843bb12014-06-22 20:50:40 +0200711 else if (brcmf_get_vif_state_any(p2p->cfg, BRCMF_VIF_STATUS_CONNECTED))
Arend van Spriel9f440b72013-02-08 15:53:36 +0100712 active = -1;
713 else
714 active = P2PAPI_SCAN_DWELL_TIME_MS;
715
716 /* Override scan params to find a peer for a connection */
717 if (num_chans == 1) {
718 active = WL_SCAN_CONNECT_DWELL_TIME_MS;
Hante Meuleman18e2f612013-02-08 15:53:49 +0100719 /* WAR to sync with presence period of VSDB GO.
Arend van Spriel9f440b72013-02-08 15:53:36 +0100720 * send probe request more frequently
721 */
722 nprobes = active / WL_SCAN_JOIN_PROBE_INTERVAL_MS;
723 } else {
724 nprobes = active / P2PAPI_SCAN_NPROBS_TIME_MS;
725 }
726
727 if (nprobes <= 0)
728 nprobes = 1;
729
730 brcmf_dbg(INFO, "nprobes # %d, active_time %d\n", nprobes, active);
731 sparams->active_time = cpu_to_le32(active);
732 sparams->nprobes = cpu_to_le32(nprobes);
733 sparams->passive_time = cpu_to_le32(-1);
734 sparams->channel_num = cpu_to_le32(num_chans &
735 BRCMF_SCAN_PARAMS_COUNT_MASK);
736 for (i = 0; i < num_chans; i++)
737 sparams->channel_list[i] = cpu_to_le16(chanspecs[i]);
738
739 /* set the escan specific parameters */
740 p2p_params->eparams.version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION);
741 p2p_params->eparams.action = cpu_to_le16(action);
742 p2p_params->eparams.sync_id = cpu_to_le16(0x1234);
743 /* perform p2p scan on primary device */
744 ret = brcmf_fil_bsscfg_data_set(vif->ifp, "p2p_scan", memblk, memsize);
745 if (!ret)
746 set_bit(BRCMF_SCAN_STATUS_BUSY, &p2p->cfg->scan_status);
747exit:
748 kfree(memblk);
749 return ret;
750}
751
752/**
753 * brcmf_p2p_run_escan() - escan callback for peer-to-peer.
754 *
755 * @cfg: driver private data for cfg80211 interface.
756 * @ndev: net device for which scan is requested.
757 * @request: scan request from cfg80211.
758 * @action: scan action.
759 *
760 * Determines the P2P discovery state based to scan request parameters and
761 * validates the channels in the request.
762 */
763static s32 brcmf_p2p_run_escan(struct brcmf_cfg80211_info *cfg,
Arend van Spriela0f472a2013-04-05 10:57:49 +0200764 struct brcmf_if *ifp,
Arend van Spriel9f440b72013-02-08 15:53:36 +0100765 struct cfg80211_scan_request *request,
766 u16 action)
767{
768 struct brcmf_p2p_info *p2p = &cfg->p2p;
769 s32 err = 0;
770 s32 search_state = WL_P2P_DISC_ST_SCAN;
771 struct brcmf_cfg80211_vif *vif;
772 struct net_device *dev = NULL;
773 int i, num_nodfs = 0;
774 u16 *chanspecs;
775
776 brcmf_dbg(TRACE, "enter\n");
777
778 if (!request) {
779 err = -EINVAL;
780 goto exit;
781 }
782
783 if (request->n_channels) {
784 chanspecs = kcalloc(request->n_channels, sizeof(*chanspecs),
785 GFP_KERNEL);
786 if (!chanspecs) {
787 err = -ENOMEM;
788 goto exit;
789 }
790 vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
791 if (vif)
792 dev = vif->wdev.netdev;
793 if (request->n_channels == 3 &&
794 request->channels[0]->hw_value == SOCIAL_CHAN_1 &&
795 request->channels[1]->hw_value == SOCIAL_CHAN_2 &&
796 request->channels[2]->hw_value == SOCIAL_CHAN_3) {
797 /* SOCIAL CHANNELS 1, 6, 11 */
798 search_state = WL_P2P_DISC_ST_SEARCH;
799 brcmf_dbg(INFO, "P2P SEARCH PHASE START\n");
Arend van Spriel967fe2c2014-03-15 17:18:21 +0100800 } else if (dev != NULL &&
801 vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) {
Arend van Spriel9f440b72013-02-08 15:53:36 +0100802 /* If you are already a GO, then do SEARCH only */
803 brcmf_dbg(INFO, "Already a GO. Do SEARCH Only\n");
804 search_state = WL_P2P_DISC_ST_SEARCH;
805 } else {
806 brcmf_dbg(INFO, "P2P SCAN STATE START\n");
807 }
808
809 /*
810 * no P2P scanning on passive or DFS channels.
811 */
812 for (i = 0; i < request->n_channels; i++) {
813 struct ieee80211_channel *chan = request->channels[i];
814
815 if (chan->flags & (IEEE80211_CHAN_RADAR |
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200816 IEEE80211_CHAN_NO_IR))
Arend van Spriel9f440b72013-02-08 15:53:36 +0100817 continue;
818
Franky Lin83cf17a2013-04-11 13:28:50 +0200819 chanspecs[i] = channel_to_chanspec(&p2p->cfg->d11inf,
820 chan);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100821 brcmf_dbg(INFO, "%d: chan=%d, channel spec=%x\n",
822 num_nodfs, chan->hw_value, chanspecs[i]);
823 num_nodfs++;
824 }
825 err = brcmf_p2p_escan(p2p, num_nodfs, chanspecs, search_state,
826 action, P2PAPI_BSSCFG_DEVICE);
Geyslan G. Bem3b1bace2013-11-15 09:21:47 -0300827 kfree(chanspecs);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100828 }
829exit:
830 if (err)
831 brcmf_err("error (%d)\n", err);
832 return err;
833}
834
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100835
836/**
837 * brcmf_p2p_find_listen_channel() - find listen channel in ie string.
838 *
839 * @ie: string of information elements.
840 * @ie_len: length of string.
841 *
842 * Scan ie for p2p ie and look for attribute 6 channel. If available determine
843 * channel and return it.
844 */
845static s32 brcmf_p2p_find_listen_channel(const u8 *ie, u32 ie_len)
846{
847 u8 channel_ie[5];
848 s32 listen_channel;
849 s32 err;
850
851 err = cfg80211_get_p2p_attr(ie, ie_len,
852 IEEE80211_P2P_ATTR_LISTEN_CHANNEL,
853 channel_ie, sizeof(channel_ie));
854 if (err < 0)
855 return err;
856
857 /* listen channel subel length format: */
858 /* 3(country) + 1(op. class) + 1(chan num) */
859 listen_channel = (s32)channel_ie[3 + 1];
860
861 if (listen_channel == SOCIAL_CHAN_1 ||
862 listen_channel == SOCIAL_CHAN_2 ||
863 listen_channel == SOCIAL_CHAN_3) {
864 brcmf_dbg(INFO, "Found my Listen Channel %d\n", listen_channel);
865 return listen_channel;
866 }
867
868 return -EPERM;
869}
870
871
Arend van Spriel9f440b72013-02-08 15:53:36 +0100872/**
873 * brcmf_p2p_scan_prep() - prepare scan based on request.
874 *
875 * @wiphy: wiphy device.
876 * @request: scan request from cfg80211.
Hante Meuleman0f8ffe12013-02-08 15:53:42 +0100877 * @vif: vif on which scan request is to be executed.
Arend van Spriel9f440b72013-02-08 15:53:36 +0100878 *
879 * Prepare the scan appropriately for type of scan requested. Overrides the
880 * escan .run() callback for peer-to-peer scanning.
881 */
882int brcmf_p2p_scan_prep(struct wiphy *wiphy,
Hante Meuleman0f8ffe12013-02-08 15:53:42 +0100883 struct cfg80211_scan_request *request,
884 struct brcmf_cfg80211_vif *vif)
Arend van Spriel9f440b72013-02-08 15:53:36 +0100885{
886 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
887 struct brcmf_p2p_info *p2p = &cfg->p2p;
888 int err = 0;
889
890 if (brcmf_p2p_scan_is_p2p_request(request)) {
891 /* find my listen channel */
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100892 err = brcmf_p2p_find_listen_channel(request->ie,
893 request->ie_len);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100894 if (err < 0)
895 return err;
896
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100897 p2p->afx_hdl.my_listen_chan = err;
898
Arend van Spriel9f440b72013-02-08 15:53:36 +0100899 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
900 brcmf_dbg(INFO, "P2P: GO_NEG_PHASE status cleared\n");
901
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100902 err = brcmf_p2p_enable_discovery(p2p);
Hante Meuleman0f8ffe12013-02-08 15:53:42 +0100903 if (err)
904 return err;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100905
Hante Meuleman0f8ffe12013-02-08 15:53:42 +0100906 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
907
908 /* override .run_escan() callback. */
Arend van Spriel9f440b72013-02-08 15:53:36 +0100909 cfg->escan_info.run = brcmf_p2p_run_escan;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100910 }
Hante Meuleman0f8ffe12013-02-08 15:53:42 +0100911 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBREQ_FLAG,
912 request->ie, request->ie_len);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100913 return err;
914}
915
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100916
917/**
Hante Meulemanf2058dd2013-02-08 15:53:50 +0100918 * brcmf_p2p_discover_listen() - set firmware to discover listen state.
919 *
920 * @p2p: p2p device.
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100921 * @channel: channel nr for discover listen.
922 * @duration: time in ms to stay on channel.
Hante Meulemanf2058dd2013-02-08 15:53:50 +0100923 *
924 */
925static s32
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100926brcmf_p2p_discover_listen(struct brcmf_p2p_info *p2p, u16 channel, u32 duration)
Hante Meulemanf2058dd2013-02-08 15:53:50 +0100927{
928 struct brcmf_cfg80211_vif *vif;
Franky Lin83cf17a2013-04-11 13:28:50 +0200929 struct brcmu_chan ch;
Hante Meulemanf2058dd2013-02-08 15:53:50 +0100930 s32 err = 0;
Hante Meulemanf2058dd2013-02-08 15:53:50 +0100931
932 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
933 if (!vif) {
934 brcmf_err("Discovery is not set, so we have nothing to do\n");
935 err = -EPERM;
936 goto exit;
937 }
938
939 if (test_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status)) {
940 brcmf_err("Previous LISTEN is not completed yet\n");
941 /* WAR: prevent cookie mismatch in wpa_supplicant return OK */
942 goto exit;
943 }
944
Franky Lin83cf17a2013-04-11 13:28:50 +0200945 ch.chnum = channel;
946 ch.bw = BRCMU_CHAN_BW_20;
947 p2p->cfg->d11inf.encchspec(&ch);
Hante Meulemanf2058dd2013-02-08 15:53:50 +0100948 err = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_LISTEN,
Franky Lin83cf17a2013-04-11 13:28:50 +0200949 ch.chspec, (u16)duration);
Hante Meulemanf2058dd2013-02-08 15:53:50 +0100950 if (!err) {
951 set_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status);
952 p2p->remain_on_channel_cookie++;
953 }
954exit:
955 return err;
956}
957
958
959/**
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100960 * brcmf_p2p_remain_on_channel() - put device on channel and stay there.
961 *
962 * @wiphy: wiphy device.
963 * @channel: channel to stay on.
964 * @duration: time in ms to remain on channel.
965 *
966 */
967int brcmf_p2p_remain_on_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
968 struct ieee80211_channel *channel,
969 unsigned int duration, u64 *cookie)
970{
971 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
972 struct brcmf_p2p_info *p2p = &cfg->p2p;
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100973 s32 err;
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100974 u16 channel_nr;
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100975
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100976 channel_nr = ieee80211_frequency_to_channel(channel->center_freq);
977 brcmf_dbg(TRACE, "Enter, channel: %d, duration ms (%d)\n", channel_nr,
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100978 duration);
979
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100980 err = brcmf_p2p_enable_discovery(p2p);
981 if (err)
982 goto exit;
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100983 err = brcmf_p2p_discover_listen(p2p, channel_nr, duration);
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100984 if (err)
985 goto exit;
986
Hante Meulemanf2058dd2013-02-08 15:53:50 +0100987 memcpy(&p2p->remain_on_channel, channel, sizeof(*channel));
988 *cookie = p2p->remain_on_channel_cookie;
Arend van Spriel1ce30862013-02-08 15:53:51 +0100989 cfg80211_ready_on_channel(wdev, *cookie, channel, duration, GFP_KERNEL);
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100990
991exit:
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100992 return err;
993}
994
995
996/**
997 * brcmf_p2p_notify_listen_complete() - p2p listen has completed.
998 *
999 * @ifp: interfac control.
1000 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1001 * @data: payload of message. Not used.
1002 *
1003 */
1004int brcmf_p2p_notify_listen_complete(struct brcmf_if *ifp,
1005 const struct brcmf_event_msg *e,
1006 void *data)
1007{
1008 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
1009 struct brcmf_p2p_info *p2p = &cfg->p2p;
1010
1011 brcmf_dbg(TRACE, "Enter\n");
Hante Meulemanf2058dd2013-02-08 15:53:50 +01001012 if (test_and_clear_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN,
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001013 &p2p->status)) {
1014 if (test_and_clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN,
1015 &p2p->status)) {
1016 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME,
1017 &p2p->status);
1018 brcmf_dbg(INFO, "Listen DONE, wake up wait_next_af\n");
1019 complete(&p2p->wait_next_af);
1020 }
1021
Hante Meulemanf2058dd2013-02-08 15:53:50 +01001022 cfg80211_remain_on_channel_expired(&ifp->vif->wdev,
1023 p2p->remain_on_channel_cookie,
Hante Meuleman0de8aac2013-02-08 15:53:38 +01001024 &p2p->remain_on_channel,
1025 GFP_KERNEL);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001026 }
Hante Meuleman0de8aac2013-02-08 15:53:38 +01001027 return 0;
1028}
1029
1030
1031/**
1032 * brcmf_p2p_cancel_remain_on_channel() - cancel p2p listen state.
1033 *
1034 * @ifp: interfac control.
1035 *
1036 */
1037void brcmf_p2p_cancel_remain_on_channel(struct brcmf_if *ifp)
1038{
1039 if (!ifp)
1040 return;
1041 brcmf_p2p_set_discover_state(ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
1042 brcmf_p2p_notify_listen_complete(ifp, NULL, NULL);
1043}
1044
1045
Arend van Spriel9f440b72013-02-08 15:53:36 +01001046/**
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001047 * brcmf_p2p_act_frm_search() - search function for action frame.
1048 *
1049 * @p2p: p2p device.
1050 * channel: channel on which action frame is to be trasmitted.
1051 *
1052 * search function to reach at common channel to send action frame. When
1053 * channel is 0 then all social channels will be used to send af
1054 */
1055static s32 brcmf_p2p_act_frm_search(struct brcmf_p2p_info *p2p, u16 channel)
1056{
1057 s32 err;
1058 u32 channel_cnt;
1059 u16 *default_chan_list;
1060 u32 i;
Franky Lin83cf17a2013-04-11 13:28:50 +02001061 struct brcmu_chan ch;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001062
1063 brcmf_dbg(TRACE, "Enter\n");
1064
1065 if (channel)
1066 channel_cnt = AF_PEER_SEARCH_CNT;
1067 else
1068 channel_cnt = SOCIAL_CHAN_CNT;
1069 default_chan_list = kzalloc(channel_cnt * sizeof(*default_chan_list),
1070 GFP_KERNEL);
1071 if (default_chan_list == NULL) {
1072 brcmf_err("channel list allocation failed\n");
1073 err = -ENOMEM;
1074 goto exit;
1075 }
Franky Lin83cf17a2013-04-11 13:28:50 +02001076 ch.bw = BRCMU_CHAN_BW_20;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001077 if (channel) {
Franky Lin83cf17a2013-04-11 13:28:50 +02001078 ch.chnum = channel;
1079 p2p->cfg->d11inf.encchspec(&ch);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001080 /* insert same channel to the chan_list */
1081 for (i = 0; i < channel_cnt; i++)
Franky Lin83cf17a2013-04-11 13:28:50 +02001082 default_chan_list[i] = ch.chspec;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001083 } else {
Franky Lin83cf17a2013-04-11 13:28:50 +02001084 ch.chnum = SOCIAL_CHAN_1;
1085 p2p->cfg->d11inf.encchspec(&ch);
1086 default_chan_list[0] = ch.chspec;
1087 ch.chnum = SOCIAL_CHAN_2;
1088 p2p->cfg->d11inf.encchspec(&ch);
1089 default_chan_list[1] = ch.chspec;
1090 ch.chnum = SOCIAL_CHAN_3;
1091 p2p->cfg->d11inf.encchspec(&ch);
1092 default_chan_list[2] = ch.chspec;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001093 }
1094 err = brcmf_p2p_escan(p2p, channel_cnt, default_chan_list,
1095 WL_P2P_DISC_ST_SEARCH, WL_ESCAN_ACTION_START,
1096 P2PAPI_BSSCFG_DEVICE);
1097 kfree(default_chan_list);
1098exit:
1099 return err;
1100}
1101
1102
1103/**
1104 * brcmf_p2p_afx_handler() - afx worker thread.
1105 *
1106 * @work:
1107 *
1108 */
1109static void brcmf_p2p_afx_handler(struct work_struct *work)
1110{
1111 struct afx_hdl *afx_hdl = container_of(work, struct afx_hdl, afx_work);
1112 struct brcmf_p2p_info *p2p = container_of(afx_hdl,
1113 struct brcmf_p2p_info,
1114 afx_hdl);
1115 s32 err;
1116
1117 if (!afx_hdl->is_active)
1118 return;
1119
1120 if (afx_hdl->is_listen && afx_hdl->my_listen_chan)
1121 /* 100ms ~ 300ms */
1122 err = brcmf_p2p_discover_listen(p2p, afx_hdl->my_listen_chan,
Akinobu Mitae00adf32013-05-07 16:18:15 -07001123 100 * (1 + prandom_u32() % 3));
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001124 else
1125 err = brcmf_p2p_act_frm_search(p2p, afx_hdl->peer_listen_chan);
1126
1127 if (err) {
1128 brcmf_err("ERROR occurred! value is (%d)\n", err);
1129 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
1130 &p2p->status))
1131 complete(&afx_hdl->act_frm_scan);
1132 }
1133}
1134
1135
1136/**
1137 * brcmf_p2p_af_searching_channel() - search channel.
1138 *
1139 * @p2p: p2p device info struct.
1140 *
1141 */
1142static s32 brcmf_p2p_af_searching_channel(struct brcmf_p2p_info *p2p)
1143{
1144 struct afx_hdl *afx_hdl = &p2p->afx_hdl;
1145 struct brcmf_cfg80211_vif *pri_vif;
1146 unsigned long duration;
1147 s32 retry;
1148
1149 brcmf_dbg(TRACE, "Enter\n");
1150
1151 pri_vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
1152
Wolfram Sang16735d02013-11-14 14:32:02 -08001153 reinit_completion(&afx_hdl->act_frm_scan);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001154 set_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status);
1155 afx_hdl->is_active = true;
1156 afx_hdl->peer_chan = P2P_INVALID_CHANNEL;
1157
1158 /* Loop to wait until we find a peer's channel or the
1159 * pending action frame tx is cancelled.
1160 */
1161 retry = 0;
1162 duration = msecs_to_jiffies(P2P_AF_FRM_SCAN_MAX_WAIT);
1163 while ((retry < P2P_CHANNEL_SYNC_RETRY) &&
1164 (afx_hdl->peer_chan == P2P_INVALID_CHANNEL)) {
1165 afx_hdl->is_listen = false;
1166 brcmf_dbg(TRACE, "Scheduling action frame for sending.. (%d)\n",
1167 retry);
1168 /* search peer on peer's listen channel */
1169 schedule_work(&afx_hdl->afx_work);
1170 wait_for_completion_timeout(&afx_hdl->act_frm_scan, duration);
1171 if ((afx_hdl->peer_chan != P2P_INVALID_CHANNEL) ||
1172 (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
1173 &p2p->status)))
1174 break;
1175
1176 if (afx_hdl->my_listen_chan) {
1177 brcmf_dbg(TRACE, "Scheduling listen peer, channel=%d\n",
1178 afx_hdl->my_listen_chan);
1179 /* listen on my listen channel */
1180 afx_hdl->is_listen = true;
1181 schedule_work(&afx_hdl->afx_work);
1182 wait_for_completion_timeout(&afx_hdl->act_frm_scan,
1183 duration);
1184 }
1185 if ((afx_hdl->peer_chan != P2P_INVALID_CHANNEL) ||
1186 (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
1187 &p2p->status)))
1188 break;
1189 retry++;
1190
1191 /* if sta is connected or connecting, sleep for a while before
1192 * retry af tx or finding a peer
1193 */
1194 if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &pri_vif->sme_state) ||
1195 test_bit(BRCMF_VIF_STATUS_CONNECTING, &pri_vif->sme_state))
1196 msleep(P2P_DEFAULT_SLEEP_TIME_VSDB);
1197 }
1198
1199 brcmf_dbg(TRACE, "Completed search/listen peer_chan=%d\n",
1200 afx_hdl->peer_chan);
1201 afx_hdl->is_active = false;
1202
1203 clear_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status);
1204
1205 return afx_hdl->peer_chan;
1206}
1207
1208
1209/**
1210 * brcmf_p2p_scan_finding_common_channel() - was escan used for finding channel
1211 *
1212 * @cfg: common configuration struct.
1213 * @bi: bss info struct, result from scan.
1214 *
1215 */
1216bool brcmf_p2p_scan_finding_common_channel(struct brcmf_cfg80211_info *cfg,
1217 struct brcmf_bss_info_le *bi)
1218
1219{
1220 struct brcmf_p2p_info *p2p = &cfg->p2p;
1221 struct afx_hdl *afx_hdl = &p2p->afx_hdl;
Franky Lin83cf17a2013-04-11 13:28:50 +02001222 struct brcmu_chan ch;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001223 u8 *ie;
1224 s32 err;
1225 u8 p2p_dev_addr[ETH_ALEN];
1226
1227 if (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status))
1228 return false;
1229
1230 if (bi == NULL) {
1231 brcmf_dbg(TRACE, "ACTION FRAME SCAN Done\n");
1232 if (afx_hdl->peer_chan == P2P_INVALID_CHANNEL)
1233 complete(&afx_hdl->act_frm_scan);
1234 return true;
1235 }
1236
1237 ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset);
1238 memset(p2p_dev_addr, 0, sizeof(p2p_dev_addr));
1239 err = cfg80211_get_p2p_attr(ie, le32_to_cpu(bi->ie_length),
1240 IEEE80211_P2P_ATTR_DEVICE_INFO,
1241 p2p_dev_addr, sizeof(p2p_dev_addr));
1242 if (err < 0)
1243 err = cfg80211_get_p2p_attr(ie, le32_to_cpu(bi->ie_length),
1244 IEEE80211_P2P_ATTR_DEVICE_ID,
1245 p2p_dev_addr, sizeof(p2p_dev_addr));
1246 if ((err >= 0) &&
dingtianhong692e5162013-12-26 19:41:34 +08001247 (ether_addr_equal(p2p_dev_addr, afx_hdl->tx_dst_addr))) {
Franky Lin83cf17a2013-04-11 13:28:50 +02001248 if (!bi->ctl_ch) {
1249 ch.chspec = le16_to_cpu(bi->chanspec);
1250 cfg->d11inf.decchspec(&ch);
1251 bi->ctl_ch = ch.chnum;
1252 }
1253 afx_hdl->peer_chan = bi->ctl_ch;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001254 brcmf_dbg(TRACE, "ACTION FRAME SCAN : Peer %pM found, channel : %d\n",
1255 afx_hdl->tx_dst_addr, afx_hdl->peer_chan);
1256 complete(&afx_hdl->act_frm_scan);
1257 }
1258 return true;
1259}
1260
1261/**
1262 * brcmf_p2p_stop_wait_next_action_frame() - finish scan if af tx complete.
1263 *
1264 * @cfg: common configuration struct.
1265 *
1266 */
1267static void
1268brcmf_p2p_stop_wait_next_action_frame(struct brcmf_cfg80211_info *cfg)
1269{
1270 struct brcmf_p2p_info *p2p = &cfg->p2p;
Arend van Spriela0f472a2013-04-05 10:57:49 +02001271 struct brcmf_if *ifp = cfg->escan_info.ifp;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001272
1273 if (test_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME, &p2p->status) &&
1274 (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status) ||
1275 test_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status))) {
1276 brcmf_dbg(TRACE, "*** Wake UP ** abort actframe iovar\n");
1277 /* if channel is not zero, "actfame" uses off channel scan.
1278 * So abort scan for off channel completion.
1279 */
1280 if (p2p->af_sent_channel)
Arend van Spriela0f472a2013-04-05 10:57:49 +02001281 brcmf_notify_escan_complete(cfg, ifp, true, true);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001282 } else if (test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN,
1283 &p2p->status)) {
1284 brcmf_dbg(TRACE, "*** Wake UP ** abort listen for next af frame\n");
1285 /* So abort scan to cancel listen */
Arend van Spriela0f472a2013-04-05 10:57:49 +02001286 brcmf_notify_escan_complete(cfg, ifp, true, true);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001287 }
1288}
1289
1290
1291/**
1292 * brcmf_p2p_gon_req_collision() - Check if go negotiaton collission
1293 *
1294 * @p2p: p2p device info struct.
1295 *
1296 * return true if recevied action frame is to be dropped.
1297 */
1298static bool
1299brcmf_p2p_gon_req_collision(struct brcmf_p2p_info *p2p, u8 *mac)
1300{
1301 struct brcmf_cfg80211_info *cfg = p2p->cfg;
1302 struct brcmf_if *ifp;
1303
1304 brcmf_dbg(TRACE, "Enter\n");
1305
1306 if (!test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status) ||
1307 !p2p->gon_req_action)
1308 return false;
1309
1310 brcmf_dbg(TRACE, "GO Negotiation Request COLLISION !!!\n");
1311 /* if sa(peer) addr is less than da(my) addr, then this device
1312 * process peer's gon request and block to send gon req.
1313 * if not (sa addr > da addr),
1314 * this device will process gon request and drop gon req of peer.
1315 */
1316 ifp = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif->ifp;
1317 if (memcmp(mac, ifp->mac_addr, ETH_ALEN) < 0) {
1318 brcmf_dbg(INFO, "Block transmit gon req !!!\n");
1319 p2p->block_gon_req_tx = true;
1320 /* if we are finding a common channel for sending af,
1321 * do not scan more to block to send current gon req
1322 */
1323 if (test_and_clear_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
1324 &p2p->status))
1325 complete(&p2p->afx_hdl.act_frm_scan);
1326 if (test_and_clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME,
1327 &p2p->status))
1328 brcmf_p2p_stop_wait_next_action_frame(cfg);
1329 return false;
1330 }
1331
1332 /* drop gon request of peer to process gon request by this device. */
1333 brcmf_dbg(INFO, "Drop received gon req !!!\n");
1334
1335 return true;
1336}
1337
1338
1339/**
Hante Meulemane6da3402013-02-08 15:53:48 +01001340 * brcmf_p2p_notify_action_frame_rx() - received action frame.
1341 *
1342 * @ifp: interfac control.
1343 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1344 * @data: payload of message, containing action frame data.
1345 *
1346 */
1347int brcmf_p2p_notify_action_frame_rx(struct brcmf_if *ifp,
1348 const struct brcmf_event_msg *e,
1349 void *data)
1350{
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001351 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
1352 struct brcmf_p2p_info *p2p = &cfg->p2p;
1353 struct afx_hdl *afx_hdl = &p2p->afx_hdl;
Hante Meulemane6da3402013-02-08 15:53:48 +01001354 struct wireless_dev *wdev;
1355 u32 mgmt_frame_len = e->datalen - sizeof(struct brcmf_rx_mgmt_data);
1356 struct brcmf_rx_mgmt_data *rxframe = (struct brcmf_rx_mgmt_data *)data;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001357 u8 *frame = (u8 *)(rxframe + 1);
1358 struct brcmf_p2p_pub_act_frame *act_frm;
1359 struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm;
Franky Lin83cf17a2013-04-11 13:28:50 +02001360 struct brcmu_chan ch;
Hante Meulemane6da3402013-02-08 15:53:48 +01001361 struct ieee80211_mgmt *mgmt_frame;
Hante Meulemane6da3402013-02-08 15:53:48 +01001362 s32 freq;
1363 u16 mgmt_type;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001364 u8 action;
Hante Meulemane6da3402013-02-08 15:53:48 +01001365
Franky Lin83cf17a2013-04-11 13:28:50 +02001366 ch.chspec = be16_to_cpu(rxframe->chanspec);
1367 cfg->d11inf.decchspec(&ch);
Hante Meulemane6da3402013-02-08 15:53:48 +01001368 /* Check if wpa_supplicant has registered for this frame */
1369 brcmf_dbg(INFO, "ifp->vif->mgmt_rx_reg %04x\n", ifp->vif->mgmt_rx_reg);
1370 mgmt_type = (IEEE80211_STYPE_ACTION & IEEE80211_FCTL_STYPE) >> 4;
1371 if ((ifp->vif->mgmt_rx_reg & BIT(mgmt_type)) == 0)
1372 return 0;
1373
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001374 brcmf_p2p_print_actframe(false, frame, mgmt_frame_len);
1375
1376 action = P2P_PAF_SUBTYPE_INVALID;
1377 if (brcmf_p2p_is_pub_action(frame, mgmt_frame_len)) {
1378 act_frm = (struct brcmf_p2p_pub_act_frame *)frame;
1379 action = act_frm->subtype;
1380 if ((action == P2P_PAF_GON_REQ) &&
1381 (brcmf_p2p_gon_req_collision(p2p, (u8 *)e->addr))) {
1382 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
1383 &p2p->status) &&
dingtianhong692e5162013-12-26 19:41:34 +08001384 (ether_addr_equal(afx_hdl->tx_dst_addr, e->addr))) {
Franky Lin83cf17a2013-04-11 13:28:50 +02001385 afx_hdl->peer_chan = ch.chnum;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001386 brcmf_dbg(INFO, "GON request: Peer found, channel=%d\n",
1387 afx_hdl->peer_chan);
1388 complete(&afx_hdl->act_frm_scan);
1389 }
1390 return 0;
1391 }
1392 /* After complete GO Negotiation, roll back to mpc mode */
1393 if ((action == P2P_PAF_GON_CONF) ||
1394 (action == P2P_PAF_PROVDIS_RSP))
Arend van Sprielf96aa072013-04-05 10:57:48 +02001395 brcmf_set_mpc(ifp, 1);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001396 if (action == P2P_PAF_GON_CONF) {
1397 brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status cleared\n");
1398 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
1399 }
1400 } else if (brcmf_p2p_is_gas_action(frame, mgmt_frame_len)) {
1401 sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame;
1402 action = sd_act_frm->action;
1403 }
1404
1405 if (test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status) &&
1406 (p2p->next_af_subtype == action)) {
1407 brcmf_dbg(TRACE, "We got a right next frame! (%d)\n", action);
1408 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME,
1409 &p2p->status);
1410 /* Stop waiting for next AF. */
1411 brcmf_p2p_stop_wait_next_action_frame(cfg);
1412 }
Hante Meulemane6da3402013-02-08 15:53:48 +01001413
1414 mgmt_frame = kzalloc(offsetof(struct ieee80211_mgmt, u) +
1415 mgmt_frame_len, GFP_KERNEL);
1416 if (!mgmt_frame) {
1417 brcmf_err("No memory available for action frame\n");
1418 return -ENOMEM;
1419 }
1420 memcpy(mgmt_frame->da, ifp->mac_addr, ETH_ALEN);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001421 brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSSID, mgmt_frame->bssid,
1422 ETH_ALEN);
Hante Meulemane6da3402013-02-08 15:53:48 +01001423 memcpy(mgmt_frame->sa, e->addr, ETH_ALEN);
1424 mgmt_frame->frame_control = cpu_to_le16(IEEE80211_STYPE_ACTION);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001425 memcpy(&mgmt_frame->u, frame, mgmt_frame_len);
Hante Meulemane6da3402013-02-08 15:53:48 +01001426 mgmt_frame_len += offsetof(struct ieee80211_mgmt, u);
1427
Franky Lin83cf17a2013-04-11 13:28:50 +02001428 freq = ieee80211_channel_to_frequency(ch.chnum,
1429 ch.band == BRCMU_CHAN_BAND_2G ?
Hante Meulemane6da3402013-02-08 15:53:48 +01001430 IEEE80211_BAND_2GHZ :
1431 IEEE80211_BAND_5GHZ);
Arend van Spriel5b57af62013-04-05 10:57:53 +02001432
1433 wdev = &ifp->vif->wdev;
Vladimir Kondratiev970fdfa2014-08-11 03:29:57 -07001434 cfg80211_rx_mgmt(wdev, freq, 0, (u8 *)mgmt_frame, mgmt_frame_len, 0);
Hante Meulemane6da3402013-02-08 15:53:48 +01001435
1436 kfree(mgmt_frame);
1437 return 0;
1438}
1439
1440
1441/**
Hante Meuleman18e2f612013-02-08 15:53:49 +01001442 * brcmf_p2p_notify_action_tx_complete() - transmit action frame complete
1443 *
1444 * @ifp: interfac control.
1445 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1446 * @data: not used.
1447 *
1448 */
1449int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp,
1450 const struct brcmf_event_msg *e,
1451 void *data)
1452{
1453 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
1454 struct brcmf_p2p_info *p2p = &cfg->p2p;
1455
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001456 brcmf_dbg(INFO, "Enter: event %s, status=%d\n",
1457 e->event_code == BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE ?
1458 "ACTION_FRAME_OFF_CHAN_COMPLETE" : "ACTION_FRAME_COMPLETE",
1459 e->status);
Hante Meuleman18e2f612013-02-08 15:53:49 +01001460
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001461 if (!test_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME, &p2p->status))
1462 return 0;
Hante Meuleman18e2f612013-02-08 15:53:49 +01001463
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001464 if (e->event_code == BRCMF_E_ACTION_FRAME_COMPLETE) {
1465 if (e->status == BRCMF_E_STATUS_SUCCESS)
1466 set_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED,
1467 &p2p->status);
1468 else {
1469 set_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
1470 /* If there is no ack, we don't need to wait for
1471 * WLC_E_ACTION_FRAME_OFFCHAN_COMPLETE event
1472 */
1473 brcmf_p2p_stop_wait_next_action_frame(cfg);
1474 }
1475
1476 } else {
1477 complete(&p2p->send_af_done);
1478 }
Hante Meuleman18e2f612013-02-08 15:53:49 +01001479 return 0;
1480}
1481
1482
1483/**
1484 * brcmf_p2p_tx_action_frame() - send action frame over fil.
1485 *
1486 * @p2p: p2p info struct for vif.
1487 * @af_params: action frame data/info.
1488 *
1489 * Send an action frame immediately without doing channel synchronization.
1490 *
1491 * This function waits for a completion event before returning.
1492 * The WLC_E_ACTION_FRAME_COMPLETE event will be received when the action
1493 * frame is transmitted.
1494 */
1495static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p,
1496 struct brcmf_fil_af_params_le *af_params)
1497{
1498 struct brcmf_cfg80211_vif *vif;
1499 s32 err = 0;
1500 s32 timeout = 0;
1501
1502 brcmf_dbg(TRACE, "Enter\n");
1503
Wolfram Sang16735d02013-11-14 14:32:02 -08001504 reinit_completion(&p2p->send_af_done);
Hante Meuleman18e2f612013-02-08 15:53:49 +01001505 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
1506 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
1507
1508 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
1509 err = brcmf_fil_bsscfg_data_set(vif->ifp, "actframe", af_params,
1510 sizeof(*af_params));
1511 if (err) {
1512 brcmf_err(" sending action frame has failed\n");
1513 goto exit;
1514 }
1515
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001516 p2p->af_sent_channel = le32_to_cpu(af_params->channel);
1517 p2p->af_tx_sent_jiffies = jiffies;
1518
Hante Meuleman18e2f612013-02-08 15:53:49 +01001519 timeout = wait_for_completion_timeout(&p2p->send_af_done,
1520 msecs_to_jiffies(P2P_AF_MAX_WAIT_TIME));
1521
1522 if (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status)) {
1523 brcmf_dbg(TRACE, "TX action frame operation is success\n");
1524 } else {
1525 err = -EIO;
1526 brcmf_dbg(TRACE, "TX action frame operation has failed\n");
1527 }
1528 /* clear status bit for action tx */
1529 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
1530 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
1531
1532exit:
1533 return err;
1534}
1535
1536
1537/**
1538 * brcmf_p2p_pub_af_tx() - public action frame tx routine.
1539 *
1540 * @cfg: driver private data for cfg80211 interface.
1541 * @af_params: action frame data/info.
1542 * @config_af_params: configuration data for action frame.
1543 *
1544 * routine which transmits ation frame public type.
1545 */
1546static s32 brcmf_p2p_pub_af_tx(struct brcmf_cfg80211_info *cfg,
1547 struct brcmf_fil_af_params_le *af_params,
1548 struct brcmf_config_af_params *config_af_params)
1549{
1550 struct brcmf_p2p_info *p2p = &cfg->p2p;
1551 struct brcmf_fil_action_frame_le *action_frame;
1552 struct brcmf_p2p_pub_act_frame *act_frm;
1553 s32 err = 0;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001554 u16 ie_len;
Hante Meuleman18e2f612013-02-08 15:53:49 +01001555
1556 action_frame = &af_params->action_frame;
1557 act_frm = (struct brcmf_p2p_pub_act_frame *)(action_frame->data);
1558
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001559 config_af_params->extra_listen = true;
1560
Hante Meuleman18e2f612013-02-08 15:53:49 +01001561 switch (act_frm->subtype) {
1562 case P2P_PAF_GON_REQ:
1563 brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status set\n");
1564 set_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
1565 config_af_params->mpc_onoff = 0;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001566 config_af_params->search_channel = true;
Hante Meuleman18e2f612013-02-08 15:53:49 +01001567 p2p->next_af_subtype = act_frm->subtype + 1;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001568 p2p->gon_req_action = true;
Hante Meuleman18e2f612013-02-08 15:53:49 +01001569 /* increase dwell time to wait for RESP frame */
1570 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1571 break;
1572 case P2P_PAF_GON_RSP:
1573 p2p->next_af_subtype = act_frm->subtype + 1;
1574 /* increase dwell time to wait for CONF frame */
1575 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1576 break;
1577 case P2P_PAF_GON_CONF:
1578 /* If we reached till GO Neg confirmation reset the filter */
1579 brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status cleared\n");
1580 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
1581 /* turn on mpc again if go nego is done */
1582 config_af_params->mpc_onoff = 1;
1583 /* minimize dwell time */
1584 af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001585 config_af_params->extra_listen = false;
Hante Meuleman18e2f612013-02-08 15:53:49 +01001586 break;
1587 case P2P_PAF_INVITE_REQ:
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001588 config_af_params->search_channel = true;
Hante Meuleman18e2f612013-02-08 15:53:49 +01001589 p2p->next_af_subtype = act_frm->subtype + 1;
1590 /* increase dwell time */
1591 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1592 break;
1593 case P2P_PAF_INVITE_RSP:
1594 /* minimize dwell time */
1595 af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001596 config_af_params->extra_listen = false;
Hante Meuleman18e2f612013-02-08 15:53:49 +01001597 break;
1598 case P2P_PAF_DEVDIS_REQ:
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001599 config_af_params->search_channel = true;
Hante Meuleman18e2f612013-02-08 15:53:49 +01001600 p2p->next_af_subtype = act_frm->subtype + 1;
1601 /* maximize dwell time to wait for RESP frame */
1602 af_params->dwell_time = cpu_to_le32(P2P_AF_LONG_DWELL_TIME);
1603 break;
1604 case P2P_PAF_DEVDIS_RSP:
1605 /* minimize dwell time */
1606 af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001607 config_af_params->extra_listen = false;
Hante Meuleman18e2f612013-02-08 15:53:49 +01001608 break;
1609 case P2P_PAF_PROVDIS_REQ:
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001610 ie_len = le16_to_cpu(action_frame->len) -
1611 offsetof(struct brcmf_p2p_pub_act_frame, elts);
1612 if (cfg80211_get_p2p_attr(&act_frm->elts[0], ie_len,
1613 IEEE80211_P2P_ATTR_GROUP_ID,
1614 NULL, 0) < 0)
1615 config_af_params->search_channel = true;
Hante Meuleman18e2f612013-02-08 15:53:49 +01001616 config_af_params->mpc_onoff = 0;
1617 p2p->next_af_subtype = act_frm->subtype + 1;
1618 /* increase dwell time to wait for RESP frame */
1619 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1620 break;
1621 case P2P_PAF_PROVDIS_RSP:
1622 /* wpa_supplicant send go nego req right after prov disc */
1623 p2p->next_af_subtype = P2P_PAF_GON_REQ;
1624 /* increase dwell time to MED level */
1625 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001626 config_af_params->extra_listen = false;
Hante Meuleman18e2f612013-02-08 15:53:49 +01001627 break;
1628 default:
1629 brcmf_err("Unknown p2p pub act frame subtype: %d\n",
1630 act_frm->subtype);
1631 err = -EINVAL;
1632 }
1633 return err;
1634}
1635
1636/**
1637 * brcmf_p2p_send_action_frame() - send action frame .
1638 *
1639 * @cfg: driver private data for cfg80211 interface.
1640 * @ndev: net device to transmit on.
1641 * @af_params: configuration data for action frame.
1642 */
1643bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info *cfg,
1644 struct net_device *ndev,
1645 struct brcmf_fil_af_params_le *af_params)
1646{
1647 struct brcmf_p2p_info *p2p = &cfg->p2p;
Arend van Spriela0f472a2013-04-05 10:57:49 +02001648 struct brcmf_if *ifp = netdev_priv(ndev);
Hante Meuleman18e2f612013-02-08 15:53:49 +01001649 struct brcmf_fil_action_frame_le *action_frame;
1650 struct brcmf_config_af_params config_af_params;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001651 struct afx_hdl *afx_hdl = &p2p->afx_hdl;
Hante Meuleman18e2f612013-02-08 15:53:49 +01001652 u16 action_frame_len;
1653 bool ack = false;
1654 u8 category;
1655 u8 action;
1656 s32 tx_retry;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001657 s32 extra_listen_time;
1658 uint delta_ms;
Hante Meuleman18e2f612013-02-08 15:53:49 +01001659
1660 action_frame = &af_params->action_frame;
1661 action_frame_len = le16_to_cpu(action_frame->len);
1662
1663 brcmf_p2p_print_actframe(true, action_frame->data, action_frame_len);
1664
1665 /* Add the default dwell time. Dwell time to stay off-channel */
1666 /* to wait for a response action frame after transmitting an */
1667 /* GO Negotiation action frame */
1668 af_params->dwell_time = cpu_to_le32(P2P_AF_DWELL_TIME);
1669
1670 category = action_frame->data[DOT11_ACTION_CAT_OFF];
1671 action = action_frame->data[DOT11_ACTION_ACT_OFF];
1672
1673 /* initialize variables */
1674 p2p->next_af_subtype = P2P_PAF_SUBTYPE_INVALID;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001675 p2p->gon_req_action = false;
Hante Meuleman18e2f612013-02-08 15:53:49 +01001676
1677 /* config parameters */
Hante Meuleman18e2f612013-02-08 15:53:49 +01001678 config_af_params.mpc_onoff = -1;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001679 config_af_params.search_channel = false;
1680 config_af_params.extra_listen = false;
Hante Meuleman18e2f612013-02-08 15:53:49 +01001681
1682 if (brcmf_p2p_is_pub_action(action_frame->data, action_frame_len)) {
1683 /* p2p public action frame process */
1684 if (brcmf_p2p_pub_af_tx(cfg, af_params, &config_af_params)) {
1685 /* Just send unknown subtype frame with */
1686 /* default parameters. */
1687 brcmf_err("P2P Public action frame, unknown subtype.\n");
1688 }
1689 } else if (brcmf_p2p_is_gas_action(action_frame->data,
1690 action_frame_len)) {
1691 /* service discovery process */
1692 if (action == P2PSD_ACTION_ID_GAS_IREQ ||
1693 action == P2PSD_ACTION_ID_GAS_CREQ) {
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001694 /* configure service discovery query frame */
1695 config_af_params.search_channel = true;
1696
Hante Meuleman18e2f612013-02-08 15:53:49 +01001697 /* save next af suptype to cancel */
1698 /* remaining dwell time */
1699 p2p->next_af_subtype = action + 1;
1700
1701 af_params->dwell_time =
1702 cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1703 } else if (action == P2PSD_ACTION_ID_GAS_IRESP ||
1704 action == P2PSD_ACTION_ID_GAS_CRESP) {
1705 /* configure service discovery response frame */
1706 af_params->dwell_time =
1707 cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1708 } else {
1709 brcmf_err("Unknown action type: %d\n", action);
1710 goto exit;
1711 }
1712 } else if (brcmf_p2p_is_p2p_action(action_frame->data,
1713 action_frame_len)) {
1714 /* do not configure anything. it will be */
1715 /* sent with a default configuration */
1716 } else {
1717 brcmf_err("Unknown Frame: category 0x%x, action 0x%x\n",
1718 category, action);
1719 return false;
1720 }
1721
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001722 /* if connecting on primary iface, sleep for a while before sending
1723 * af tx for VSDB
1724 */
1725 if (test_bit(BRCMF_VIF_STATUS_CONNECTING,
1726 &p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->sme_state))
1727 msleep(50);
1728
Hante Meuleman18e2f612013-02-08 15:53:49 +01001729 /* if scan is ongoing, abort current scan. */
1730 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
1731 brcmf_abort_scanning(cfg);
1732
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001733 memcpy(afx_hdl->tx_dst_addr, action_frame->da, ETH_ALEN);
1734
Hante Meuleman18e2f612013-02-08 15:53:49 +01001735 /* To make sure to send successfully action frame, turn off mpc */
1736 if (config_af_params.mpc_onoff == 0)
Arend van Spriela0f472a2013-04-05 10:57:49 +02001737 brcmf_set_mpc(ifp, 0);
Hante Meuleman18e2f612013-02-08 15:53:49 +01001738
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001739 /* set status and destination address before sending af */
1740 if (p2p->next_af_subtype != P2P_PAF_SUBTYPE_INVALID) {
1741 /* set status to cancel the remained dwell time in rx process */
1742 set_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status);
1743 }
1744
1745 p2p->af_sent_channel = 0;
1746 set_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME, &p2p->status);
1747 /* validate channel and p2p ies */
1748 if (config_af_params.search_channel &&
1749 IS_P2P_SOCIAL_CHANNEL(le32_to_cpu(af_params->channel)) &&
1750 p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif->saved_ie.probe_req_ie_len) {
1751 afx_hdl = &p2p->afx_hdl;
1752 afx_hdl->peer_listen_chan = le32_to_cpu(af_params->channel);
1753
1754 if (brcmf_p2p_af_searching_channel(p2p) ==
1755 P2P_INVALID_CHANNEL) {
1756 brcmf_err("Couldn't find peer's channel.\n");
1757 goto exit;
1758 }
1759
1760 /* Abort scan even for VSDB scenarios. Scan gets aborted in
1761 * firmware but after the check of piggyback algorithm. To take
1762 * care of current piggback algo, lets abort the scan here
1763 * itself.
1764 */
Arend van Spriela0f472a2013-04-05 10:57:49 +02001765 brcmf_notify_escan_complete(cfg, ifp, true, true);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001766
1767 /* update channel */
1768 af_params->channel = cpu_to_le32(afx_hdl->peer_chan);
1769 }
1770
Hante Meuleman18e2f612013-02-08 15:53:49 +01001771 tx_retry = 0;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001772 while (!p2p->block_gon_req_tx &&
1773 (ack == false) && (tx_retry < P2P_AF_TX_MAX_RETRY)) {
Hante Meuleman18e2f612013-02-08 15:53:49 +01001774 ack = !brcmf_p2p_tx_action_frame(p2p, af_params);
1775 tx_retry++;
1776 }
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001777 if (ack == false) {
Hante Meuleman18e2f612013-02-08 15:53:49 +01001778 brcmf_err("Failed to send Action Frame(retry %d)\n", tx_retry);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001779 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
1780 }
Hante Meuleman18e2f612013-02-08 15:53:49 +01001781
1782exit:
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001783 clear_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME, &p2p->status);
1784
1785 /* WAR: sometimes dongle does not keep the dwell time of 'actframe'.
1786 * if we coundn't get the next action response frame and dongle does
1787 * not keep the dwell time, go to listen state again to get next action
1788 * response frame.
1789 */
1790 if (ack && config_af_params.extra_listen && !p2p->block_gon_req_tx &&
1791 test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status) &&
1792 p2p->af_sent_channel == afx_hdl->my_listen_chan) {
1793 delta_ms = jiffies_to_msecs(jiffies - p2p->af_tx_sent_jiffies);
1794 if (le32_to_cpu(af_params->dwell_time) > delta_ms)
1795 extra_listen_time = le32_to_cpu(af_params->dwell_time) -
1796 delta_ms;
1797 else
1798 extra_listen_time = 0;
1799 if (extra_listen_time > 50) {
1800 set_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN,
1801 &p2p->status);
1802 brcmf_dbg(INFO, "Wait more time! actual af time:%d, calculated extra listen:%d\n",
1803 le32_to_cpu(af_params->dwell_time),
1804 extra_listen_time);
1805 extra_listen_time += 100;
1806 if (!brcmf_p2p_discover_listen(p2p,
1807 p2p->af_sent_channel,
1808 extra_listen_time)) {
1809 unsigned long duration;
1810
1811 extra_listen_time += 100;
1812 duration = msecs_to_jiffies(extra_listen_time);
1813 wait_for_completion_timeout(&p2p->wait_next_af,
1814 duration);
1815 }
1816 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN,
1817 &p2p->status);
1818 }
1819 }
1820
1821 if (p2p->block_gon_req_tx) {
1822 /* if ack is true, supplicant will wait more time(100ms).
1823 * so we will return it as a success to get more time .
1824 */
1825 p2p->block_gon_req_tx = false;
1826 ack = true;
1827 }
1828
1829 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status);
Hante Meuleman18e2f612013-02-08 15:53:49 +01001830 /* if all done, turn mpc on again */
1831 if (config_af_params.mpc_onoff == 1)
Arend van Spriela0f472a2013-04-05 10:57:49 +02001832 brcmf_set_mpc(ifp, 1);
Hante Meuleman18e2f612013-02-08 15:53:49 +01001833
1834 return ack;
1835}
1836
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001837/**
1838 * brcmf_p2p_notify_rx_mgmt_p2p_probereq() - Event handler for p2p probe req.
1839 *
1840 * @ifp: interface pointer for which event was received.
1841 * @e: even message.
1842 * @data: payload of event message (probe request).
1843 */
1844s32 brcmf_p2p_notify_rx_mgmt_p2p_probereq(struct brcmf_if *ifp,
1845 const struct brcmf_event_msg *e,
1846 void *data)
1847{
1848 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
1849 struct brcmf_p2p_info *p2p = &cfg->p2p;
1850 struct afx_hdl *afx_hdl = &p2p->afx_hdl;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001851 struct brcmf_cfg80211_vif *vif = ifp->vif;
1852 struct brcmf_rx_mgmt_data *rxframe = (struct brcmf_rx_mgmt_data *)data;
1853 u16 chanspec = be16_to_cpu(rxframe->chanspec);
Franky Lin83cf17a2013-04-11 13:28:50 +02001854 struct brcmu_chan ch;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001855 u8 *mgmt_frame;
1856 u32 mgmt_frame_len;
1857 s32 freq;
1858 u16 mgmt_type;
1859
1860 brcmf_dbg(INFO, "Enter: event %d reason %d\n", e->event_code,
1861 e->reason);
1862
Franky Lin83cf17a2013-04-11 13:28:50 +02001863 ch.chspec = be16_to_cpu(rxframe->chanspec);
1864 cfg->d11inf.decchspec(&ch);
1865
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001866 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status) &&
dingtianhong692e5162013-12-26 19:41:34 +08001867 (ether_addr_equal(afx_hdl->tx_dst_addr, e->addr))) {
Franky Lin83cf17a2013-04-11 13:28:50 +02001868 afx_hdl->peer_chan = ch.chnum;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001869 brcmf_dbg(INFO, "PROBE REQUEST: Peer found, channel=%d\n",
1870 afx_hdl->peer_chan);
1871 complete(&afx_hdl->act_frm_scan);
1872 }
1873
1874 /* Firmware sends us two proberesponses for each idx one. At the */
1875 /* moment anything but bsscfgidx 0 is passed up to supplicant */
1876 if (e->bsscfgidx == 0)
1877 return 0;
1878
1879 /* Filter any P2P probe reqs arriving during the GO-NEG Phase */
1880 if (test_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status)) {
1881 brcmf_dbg(INFO, "Filtering P2P probe_req in GO-NEG phase\n");
1882 return 0;
1883 }
1884
1885 /* Check if wpa_supplicant has registered for this frame */
1886 brcmf_dbg(INFO, "vif->mgmt_rx_reg %04x\n", vif->mgmt_rx_reg);
1887 mgmt_type = (IEEE80211_STYPE_PROBE_REQ & IEEE80211_FCTL_STYPE) >> 4;
1888 if ((vif->mgmt_rx_reg & BIT(mgmt_type)) == 0)
1889 return 0;
1890
1891 mgmt_frame = (u8 *)(rxframe + 1);
1892 mgmt_frame_len = e->datalen - sizeof(*rxframe);
Franky Lin83cf17a2013-04-11 13:28:50 +02001893 freq = ieee80211_channel_to_frequency(ch.chnum,
1894 ch.band == BRCMU_CHAN_BAND_2G ?
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001895 IEEE80211_BAND_2GHZ :
1896 IEEE80211_BAND_5GHZ);
Arend van Sprielbffc61c2013-04-05 10:57:52 +02001897
Vladimir Kondratiev970fdfa2014-08-11 03:29:57 -07001898 cfg80211_rx_mgmt(&vif->wdev, freq, 0, mgmt_frame, mgmt_frame_len, 0);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001899
1900 brcmf_dbg(INFO, "mgmt_frame_len (%d) , e->datalen (%d), chanspec (%04x), freq (%d)\n",
1901 mgmt_frame_len, e->datalen, chanspec, freq);
1902
1903 return 0;
1904}
1905
Hante Meuleman18e2f612013-02-08 15:53:49 +01001906
1907/**
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01001908 * brcmf_p2p_get_current_chanspec() - Get current operation channel.
1909 *
1910 * @p2p: P2P specific data.
1911 * @chanspec: chanspec to be returned.
1912 */
1913static void brcmf_p2p_get_current_chanspec(struct brcmf_p2p_info *p2p,
1914 u16 *chanspec)
1915{
1916 struct brcmf_if *ifp;
Hante Meuleman15a953d2013-05-27 21:09:54 +02001917 u8 mac_addr[ETH_ALEN];
Franky Lin83cf17a2013-04-11 13:28:50 +02001918 struct brcmu_chan ch;
Hante Meuleman15a953d2013-05-27 21:09:54 +02001919 struct brcmf_bss_info_le *bi;
1920 u8 *buf;
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01001921
1922 ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
1923
Hante Meuleman15a953d2013-05-27 21:09:54 +02001924 if (brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSSID, mac_addr,
1925 ETH_ALEN) == 0) {
1926 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
1927 if (buf != NULL) {
1928 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
1929 if (brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
1930 buf, WL_BSS_INFO_MAX) == 0) {
1931 bi = (struct brcmf_bss_info_le *)(buf + 4);
1932 *chanspec = le16_to_cpu(bi->chanspec);
1933 kfree(buf);
1934 return;
1935 }
1936 kfree(buf);
1937 }
1938 }
1939 /* Use default channel for P2P */
1940 ch.chnum = BRCMF_P2P_TEMP_CHAN;
Franky Lin83cf17a2013-04-11 13:28:50 +02001941 ch.bw = BRCMU_CHAN_BW_20;
1942 p2p->cfg->d11inf.encchspec(&ch);
1943 *chanspec = ch.chspec;
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01001944}
1945
1946/**
1947 * Change a P2P Role.
1948 * Parameters:
1949 * @mac: MAC address of the BSS to change a role
1950 * Returns 0 if success.
1951 */
1952int brcmf_p2p_ifchange(struct brcmf_cfg80211_info *cfg,
1953 enum brcmf_fil_p2p_if_types if_type)
1954{
1955 struct brcmf_p2p_info *p2p = &cfg->p2p;
1956 struct brcmf_cfg80211_vif *vif;
1957 struct brcmf_fil_p2p_if_le if_request;
1958 s32 err;
1959 u16 chanspec;
1960
1961 brcmf_dbg(TRACE, "Enter\n");
1962
1963 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
1964 if (!vif) {
1965 brcmf_err("vif for P2PAPI_BSSCFG_PRIMARY does not exist\n");
1966 return -EPERM;
1967 }
Arend van Spriela0f472a2013-04-05 10:57:49 +02001968 brcmf_notify_escan_complete(cfg, vif->ifp, true, true);
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01001969 vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
1970 if (!vif) {
1971 brcmf_err("vif for P2PAPI_BSSCFG_CONNECTION does not exist\n");
1972 return -EPERM;
1973 }
Arend van Sprielf96aa072013-04-05 10:57:48 +02001974 brcmf_set_mpc(vif->ifp, 0);
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01001975
1976 /* In concurrency case, STA may be already associated in a particular */
1977 /* channel. so retrieve the current channel of primary interface and */
1978 /* then start the virtual interface on that. */
1979 brcmf_p2p_get_current_chanspec(p2p, &chanspec);
1980
1981 if_request.type = cpu_to_le16((u16)if_type);
1982 if_request.chspec = cpu_to_le16(chanspec);
1983 memcpy(if_request.addr, p2p->int_addr, sizeof(if_request.addr));
1984
1985 brcmf_cfg80211_arm_vif_event(cfg, vif);
1986 err = brcmf_fil_iovar_data_set(vif->ifp, "p2p_ifupd", &if_request,
1987 sizeof(if_request));
1988 if (err) {
1989 brcmf_err("p2p_ifupd FAILED, err=%d\n", err);
1990 brcmf_cfg80211_arm_vif_event(cfg, NULL);
1991 return err;
1992 }
1993 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_CHANGE,
1994 msecs_to_jiffies(1500));
1995 brcmf_cfg80211_arm_vif_event(cfg, NULL);
1996 if (!err) {
1997 brcmf_err("No BRCMF_E_IF_CHANGE event received\n");
1998 return -EIO;
1999 }
2000
2001 err = brcmf_fil_cmd_int_set(vif->ifp, BRCMF_C_SET_SCB_TIMEOUT,
2002 BRCMF_SCB_TIMEOUT_VALUE);
2003
2004 return err;
2005}
2006
2007static int brcmf_p2p_request_p2p_if(struct brcmf_p2p_info *p2p,
2008 struct brcmf_if *ifp, u8 ea[ETH_ALEN],
Arend van Sprield3c0b632013-02-08 15:53:37 +01002009 enum brcmf_fil_p2p_if_types iftype)
2010{
2011 struct brcmf_fil_p2p_if_le if_request;
Arend van Sprield3c0b632013-02-08 15:53:37 +01002012 int err;
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01002013 u16 chanspec;
Arend van Sprield3c0b632013-02-08 15:53:37 +01002014
2015 /* we need a default channel */
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01002016 brcmf_p2p_get_current_chanspec(p2p, &chanspec);
Arend van Sprield3c0b632013-02-08 15:53:37 +01002017
2018 /* fill the firmware request */
2019 memcpy(if_request.addr, ea, ETH_ALEN);
Hante Meuleman7ee2d922013-02-08 15:53:43 +01002020 if_request.type = cpu_to_le16((u16)iftype);
Arend van Sprield3c0b632013-02-08 15:53:37 +01002021 if_request.chspec = cpu_to_le16(chanspec);
2022
2023 err = brcmf_fil_iovar_data_set(ifp, "p2p_ifadd", &if_request,
2024 sizeof(if_request));
2025 if (err)
2026 return err;
2027
Arend van Sprield3c0b632013-02-08 15:53:37 +01002028 return err;
2029}
2030
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01002031static int brcmf_p2p_disable_p2p_if(struct brcmf_cfg80211_vif *vif)
2032{
2033 struct brcmf_cfg80211_info *cfg = wdev_to_cfg(&vif->wdev);
2034 struct net_device *pri_ndev = cfg_to_ndev(cfg);
2035 struct brcmf_if *ifp = netdev_priv(pri_ndev);
2036 u8 *addr = vif->wdev.netdev->dev_addr;
2037
2038 return brcmf_fil_iovar_data_set(ifp, "p2p_ifdis", addr, ETH_ALEN);
2039}
2040
2041static int brcmf_p2p_release_p2p_if(struct brcmf_cfg80211_vif *vif)
2042{
2043 struct brcmf_cfg80211_info *cfg = wdev_to_cfg(&vif->wdev);
2044 struct net_device *pri_ndev = cfg_to_ndev(cfg);
2045 struct brcmf_if *ifp = netdev_priv(pri_ndev);
2046 u8 *addr = vif->wdev.netdev->dev_addr;
2047
2048 return brcmf_fil_iovar_data_set(ifp, "p2p_ifdel", addr, ETH_ALEN);
2049}
2050
Arend van Spriel9f440b72013-02-08 15:53:36 +01002051/**
Arend van Spriel27f10e32013-04-05 10:57:50 +02002052 * brcmf_p2p_create_p2pdev() - create a P2P_DEVICE virtual interface.
2053 *
2054 * @p2p: P2P specific data.
2055 * @wiphy: wiphy device of new interface.
2056 * @addr: mac address for this new interface.
2057 */
2058static struct wireless_dev *brcmf_p2p_create_p2pdev(struct brcmf_p2p_info *p2p,
2059 struct wiphy *wiphy,
2060 u8 *addr)
2061{
2062 struct brcmf_cfg80211_vif *p2p_vif;
2063 struct brcmf_if *p2p_ifp;
2064 struct brcmf_if *pri_ifp;
2065 int err;
Hante Meuleman37a869e2015-10-29 20:33:17 +01002066 u32 bsscfgidx;
Arend van Spriel27f10e32013-04-05 10:57:50 +02002067
2068 if (p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
2069 return ERR_PTR(-ENOSPC);
2070
2071 p2p_vif = brcmf_alloc_vif(p2p->cfg, NL80211_IFTYPE_P2P_DEVICE,
2072 false);
2073 if (IS_ERR(p2p_vif)) {
2074 brcmf_err("could not create discovery vif\n");
2075 return (struct wireless_dev *)p2p_vif;
2076 }
2077
Arend van Spriel27f10e32013-04-05 10:57:50 +02002078 pri_ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02002079 brcmf_p2p_generate_bss_mac(p2p, addr);
Arend van Spriel27f10e32013-04-05 10:57:50 +02002080 brcmf_p2p_set_firmware(pri_ifp, p2p->dev_addr);
2081
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02002082 brcmf_cfg80211_arm_vif_event(p2p->cfg, p2p_vif);
Hante Meulemancb8dc712015-09-18 22:08:18 +02002083 brcmf_fweh_p2pdev_setup(pri_ifp, true);
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02002084
Arend van Spriel27f10e32013-04-05 10:57:50 +02002085 /* Initialize P2P Discovery in the firmware */
2086 err = brcmf_fil_iovar_int_set(pri_ifp, "p2p_disc", 1);
2087 if (err < 0) {
2088 brcmf_err("set p2p_disc error\n");
Hante Meulemancb8dc712015-09-18 22:08:18 +02002089 brcmf_fweh_p2pdev_setup(pri_ifp, false);
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02002090 brcmf_cfg80211_arm_vif_event(p2p->cfg, NULL);
2091 goto fail;
Arend van Spriel27f10e32013-04-05 10:57:50 +02002092 }
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02002093
2094 /* wait for firmware event */
2095 err = brcmf_cfg80211_wait_vif_event_timeout(p2p->cfg, BRCMF_E_IF_ADD,
2096 msecs_to_jiffies(1500));
2097 brcmf_cfg80211_arm_vif_event(p2p->cfg, NULL);
Hante Meulemancb8dc712015-09-18 22:08:18 +02002098 brcmf_fweh_p2pdev_setup(pri_ifp, false);
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02002099 if (!err) {
2100 brcmf_err("timeout occurred\n");
2101 err = -EIO;
2102 goto fail;
2103 }
2104
2105 /* discovery interface created */
2106 p2p_ifp = p2p_vif->ifp;
2107 p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif = p2p_vif;
2108 memcpy(p2p_ifp->mac_addr, p2p->dev_addr, ETH_ALEN);
2109 memcpy(&p2p_vif->wdev.address, p2p->dev_addr, sizeof(p2p->dev_addr));
2110
2111 /* verify bsscfg index for P2P discovery */
Hante Meuleman37a869e2015-10-29 20:33:17 +01002112 err = brcmf_fil_iovar_int_get(pri_ifp, "p2p_dev", &bsscfgidx);
Arend van Spriel27f10e32013-04-05 10:57:50 +02002113 if (err < 0) {
2114 brcmf_err("retrieving discover bsscfg index failed\n");
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02002115 goto fail;
Arend van Spriel27f10e32013-04-05 10:57:50 +02002116 }
2117
Hante Meuleman37a869e2015-10-29 20:33:17 +01002118 WARN_ON(p2p_ifp->bsscfgidx != bsscfgidx);
Arend van Spriel27f10e32013-04-05 10:57:50 +02002119
2120 init_completion(&p2p->send_af_done);
2121 INIT_WORK(&p2p->afx_hdl.afx_work, brcmf_p2p_afx_handler);
2122 init_completion(&p2p->afx_hdl.act_frm_scan);
2123 init_completion(&p2p->wait_next_af);
2124
2125 return &p2p_vif->wdev;
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02002126
2127fail:
Arend van Spriel427dec52014-01-06 12:40:47 +01002128 brcmf_free_vif(p2p_vif);
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02002129 return ERR_PTR(err);
Arend van Spriel27f10e32013-04-05 10:57:50 +02002130}
2131
2132/**
Arend van Spriel9f440b72013-02-08 15:53:36 +01002133 * brcmf_p2p_add_vif() - create a new P2P virtual interface.
2134 *
2135 * @wiphy: wiphy device of new interface.
2136 * @name: name of the new interface.
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002137 * @name_assign_type: origin of the interface name
Arend van Spriel9f440b72013-02-08 15:53:36 +01002138 * @type: nl80211 interface type.
Arend van Spriel27f10e32013-04-05 10:57:50 +02002139 * @flags: not used.
2140 * @params: contains mac address for P2P device.
Arend van Spriel9f440b72013-02-08 15:53:36 +01002141 */
2142struct wireless_dev *brcmf_p2p_add_vif(struct wiphy *wiphy, const char *name,
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002143 unsigned char name_assign_type,
Arend van Spriel9f440b72013-02-08 15:53:36 +01002144 enum nl80211_iftype type, u32 *flags,
2145 struct vif_params *params)
2146{
Arend van Sprield3c0b632013-02-08 15:53:37 +01002147 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2148 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
2149 struct brcmf_cfg80211_vif *vif;
2150 enum brcmf_fil_p2p_if_types iftype;
Arend van Sprield3c0b632013-02-08 15:53:37 +01002151 int err;
2152
2153 if (brcmf_cfg80211_vif_event_armed(cfg))
2154 return ERR_PTR(-EBUSY);
2155
Arend van Spriel9f440b72013-02-08 15:53:36 +01002156 brcmf_dbg(INFO, "adding vif \"%s\" (type=%d)\n", name, type);
Arend van Sprield3c0b632013-02-08 15:53:37 +01002157
2158 switch (type) {
2159 case NL80211_IFTYPE_P2P_CLIENT:
2160 iftype = BRCMF_FIL_P2P_IF_CLIENT;
Arend van Sprield3c0b632013-02-08 15:53:37 +01002161 break;
2162 case NL80211_IFTYPE_P2P_GO:
2163 iftype = BRCMF_FIL_P2P_IF_GO;
Arend van Sprield3c0b632013-02-08 15:53:37 +01002164 break;
Arend van Spriel27f10e32013-04-05 10:57:50 +02002165 case NL80211_IFTYPE_P2P_DEVICE:
2166 return brcmf_p2p_create_p2pdev(&cfg->p2p, wiphy,
2167 params->macaddr);
Arend van Sprield3c0b632013-02-08 15:53:37 +01002168 default:
2169 return ERR_PTR(-EOPNOTSUPP);
2170 }
2171
2172 vif = brcmf_alloc_vif(cfg, type, false);
Hante Meuleman7ee2d922013-02-08 15:53:43 +01002173 if (IS_ERR(vif))
2174 return (struct wireless_dev *)vif;
Arend van Sprield3c0b632013-02-08 15:53:37 +01002175 brcmf_cfg80211_arm_vif_event(cfg, vif);
2176
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01002177 err = brcmf_p2p_request_p2p_if(&cfg->p2p, ifp, cfg->p2p.int_addr,
2178 iftype);
Hante Meuleman7ee2d922013-02-08 15:53:43 +01002179 if (err) {
2180 brcmf_cfg80211_arm_vif_event(cfg, NULL);
Arend van Sprield3c0b632013-02-08 15:53:37 +01002181 goto fail;
Hante Meuleman7ee2d922013-02-08 15:53:43 +01002182 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01002183
2184 /* wait for firmware event */
2185 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_ADD,
2186 msecs_to_jiffies(1500));
2187 brcmf_cfg80211_arm_vif_event(cfg, NULL);
2188 if (!err) {
2189 brcmf_err("timeout occurred\n");
2190 err = -EIO;
2191 goto fail;
2192 }
2193
2194 /* interface created in firmware */
2195 ifp = vif->ifp;
2196 if (!ifp) {
2197 brcmf_err("no if pointer provided\n");
2198 err = -ENOENT;
Hante Meuleman7ee2d922013-02-08 15:53:43 +01002199 goto fail;
Arend van Sprield3c0b632013-02-08 15:53:37 +01002200 }
2201
2202 strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1);
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002203 ifp->ndev->name_assign_type = name_assign_type;
Hante Meuleman4b3a89d2013-02-08 15:54:01 +01002204 err = brcmf_net_attach(ifp, true);
2205 if (err) {
2206 brcmf_err("Registering netdevice failed\n");
2207 goto fail;
2208 }
Arend van Sprielcbb371d2013-05-27 21:09:57 +02002209
Hante Meuleman7ee2d922013-02-08 15:53:43 +01002210 cfg->p2p.bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = vif;
2211 /* Disable firmware roaming for P2P interface */
2212 brcmf_fil_iovar_int_set(ifp, "roam_off", 1);
2213 if (iftype == BRCMF_FIL_P2P_IF_GO) {
2214 /* set station timeout for p2p */
2215 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCB_TIMEOUT,
2216 BRCMF_SCB_TIMEOUT_VALUE);
2217 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01002218 return &ifp->vif->wdev;
2219
2220fail:
Arend van Spriel427dec52014-01-06 12:40:47 +01002221 brcmf_free_vif(vif);
Arend van Sprield3c0b632013-02-08 15:53:37 +01002222 return ERR_PTR(err);
Arend van Spriel9f440b72013-02-08 15:53:36 +01002223}
2224
2225/**
2226 * brcmf_p2p_del_vif() - delete a P2P virtual interface.
2227 *
2228 * @wiphy: wiphy device of interface.
2229 * @wdev: wireless device of interface.
Arend van Spriel9f440b72013-02-08 15:53:36 +01002230 */
2231int brcmf_p2p_del_vif(struct wiphy *wiphy, struct wireless_dev *wdev)
2232{
Arend van Sprield3c0b632013-02-08 15:53:37 +01002233 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01002234 struct brcmf_p2p_info *p2p = &cfg->p2p;
Arend van Spriel9f440b72013-02-08 15:53:36 +01002235 struct brcmf_cfg80211_vif *vif;
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01002236 unsigned long jiffie_timeout = msecs_to_jiffies(1500);
2237 bool wait_for_disable = false;
Arend van Sprield3c0b632013-02-08 15:53:37 +01002238 int err;
Arend van Spriel9f440b72013-02-08 15:53:36 +01002239
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01002240 brcmf_dbg(TRACE, "delete P2P vif\n");
Arend van Spriel9f440b72013-02-08 15:53:36 +01002241 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
Arend van Sprield3c0b632013-02-08 15:53:37 +01002242
Hante Meulemana2044d92015-09-18 22:08:16 +02002243 brcmf_cfg80211_arm_vif_event(cfg, vif);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01002244 switch (vif->wdev.iftype) {
2245 case NL80211_IFTYPE_P2P_CLIENT:
2246 if (test_bit(BRCMF_VIF_STATUS_DISCONNECTING, &vif->sme_state))
2247 wait_for_disable = true;
2248 break;
2249
2250 case NL80211_IFTYPE_P2P_GO:
2251 if (!brcmf_p2p_disable_p2p_if(vif))
2252 wait_for_disable = true;
2253 break;
2254
2255 case NL80211_IFTYPE_P2P_DEVICE:
Hante Meuleman9831bcb2015-09-18 22:08:12 +02002256 if (!p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
2257 return 0;
Arend van Sprielf37d69a2015-06-11 00:12:21 +02002258 brcmf_p2p_cancel_remain_on_channel(vif->ifp);
2259 brcmf_p2p_deinit_discovery(p2p);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01002260 default:
2261 return -ENOTSUPP;
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01002262 }
2263
Hante Meuleman6eda4e22013-02-08 15:54:02 +01002264 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
2265 brcmf_dbg(INFO, "P2P: GO_NEG_PHASE status cleared\n");
2266
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01002267 if (wait_for_disable)
Hante Meuleman7ee2d922013-02-08 15:53:43 +01002268 wait_for_completion_timeout(&cfg->vif_disabled,
2269 msecs_to_jiffies(500));
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01002270
Hante Meulemana2044d92015-09-18 22:08:16 +02002271 err = 0;
2272 if (vif->wdev.iftype != NL80211_IFTYPE_P2P_DEVICE) {
2273 brcmf_vif_clear_mgmt_ies(vif);
2274 err = brcmf_p2p_release_p2p_if(vif);
2275 }
Hante Meuleman7ee2d922013-02-08 15:53:43 +01002276 if (!err) {
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01002277 /* wait for firmware event */
2278 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_DEL,
2279 jiffie_timeout);
Hante Meuleman7ee2d922013-02-08 15:53:43 +01002280 if (!err)
2281 err = -EIO;
2282 else
2283 err = 0;
2284 }
Hante Meulemana2044d92015-09-18 22:08:16 +02002285 if (err)
2286 brcmf_remove_interface(vif->ifp);
2287
Arend van Sprield3c0b632013-02-08 15:53:37 +01002288 brcmf_cfg80211_arm_vif_event(cfg, NULL);
Hante Meulemana2044d92015-09-18 22:08:16 +02002289 if (vif->wdev.iftype != NL80211_IFTYPE_P2P_DEVICE)
2290 p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = NULL;
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01002291
2292 return err;
Arend van Spriel9f440b72013-02-08 15:53:36 +01002293}
Arend van Spriel27f10e32013-04-05 10:57:50 +02002294
Hante Meuleman9831bcb2015-09-18 22:08:12 +02002295void brcmf_p2p_ifp_removed(struct brcmf_if *ifp)
2296{
2297 struct brcmf_cfg80211_info *cfg;
2298 struct brcmf_cfg80211_vif *vif;
2299
2300 brcmf_dbg(INFO, "P2P: device interface removed\n");
2301 vif = ifp->vif;
2302 cfg = wdev_to_cfg(&vif->wdev);
2303 cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif = NULL;
2304 rtnl_lock();
2305 cfg80211_unregister_wdev(&vif->wdev);
2306 rtnl_unlock();
2307 brcmf_free_vif(vif);
2308}
2309
Arend van Spriel27f10e32013-04-05 10:57:50 +02002310int brcmf_p2p_start_device(struct wiphy *wiphy, struct wireless_dev *wdev)
2311{
2312 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2313 struct brcmf_p2p_info *p2p = &cfg->p2p;
2314 struct brcmf_cfg80211_vif *vif;
2315 int err;
2316
2317 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
2318 mutex_lock(&cfg->usr_sync);
2319 err = brcmf_p2p_enable_discovery(p2p);
2320 if (!err)
2321 set_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state);
2322 mutex_unlock(&cfg->usr_sync);
2323 return err;
2324}
2325
2326void brcmf_p2p_stop_device(struct wiphy *wiphy, struct wireless_dev *wdev)
2327{
2328 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2329 struct brcmf_p2p_info *p2p = &cfg->p2p;
2330 struct brcmf_cfg80211_vif *vif;
2331
2332 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
Hante Meulemand1bb34c2015-09-18 22:08:13 +02002333 /* This call can be result of the unregister_wdev call. In that case
2334 * we dont want to do anything anymore. Just return. The config vif
2335 * will have been cleared at this point.
2336 */
2337 if (p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif == vif) {
2338 mutex_lock(&cfg->usr_sync);
Hante Meulemana2044d92015-09-18 22:08:16 +02002339 /* Set the discovery state to SCAN */
2340 (void)brcmf_p2p_set_discover_state(vif->ifp,
2341 WL_P2P_DISC_ST_SCAN, 0, 0);
Hante Meulemand1bb34c2015-09-18 22:08:13 +02002342 brcmf_abort_scanning(cfg);
2343 clear_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state);
2344 mutex_unlock(&cfg->usr_sync);
2345 }
Arend van Spriel27f10e32013-04-05 10:57:50 +02002346}
Arend van Spriel55479df2015-06-11 00:12:22 +02002347
2348/**
2349 * brcmf_p2p_attach() - attach for P2P.
2350 *
2351 * @cfg: driver private data for cfg80211 interface.
Hante Meuleman2b76acd2015-10-08 20:33:15 +02002352 * @p2pdev_forced: create p2p device interface at attach.
Arend van Spriel55479df2015-06-11 00:12:22 +02002353 */
Hante Meulemanae7c03f2015-09-18 22:08:08 +02002354s32 brcmf_p2p_attach(struct brcmf_cfg80211_info *cfg, bool p2pdev_forced)
Arend van Spriel55479df2015-06-11 00:12:22 +02002355{
Arend van Spriel55479df2015-06-11 00:12:22 +02002356 struct brcmf_p2p_info *p2p;
Hante Meuleman2b76acd2015-10-08 20:33:15 +02002357 struct brcmf_if *pri_ifp;
Arend van Spriel55479df2015-06-11 00:12:22 +02002358 s32 err = 0;
Hante Meuleman2b76acd2015-10-08 20:33:15 +02002359 void *err_ptr;
Arend van Spriel55479df2015-06-11 00:12:22 +02002360
2361 p2p = &cfg->p2p;
2362 p2p->cfg = cfg;
2363
Hante Meuleman2b76acd2015-10-08 20:33:15 +02002364 pri_ifp = brcmf_get_ifp(cfg->pub, 0);
Arend van Spriel55479df2015-06-11 00:12:22 +02002365 p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif = pri_ifp->vif;
2366
Hante Meulemanae7c03f2015-09-18 22:08:08 +02002367 if (p2pdev_forced) {
Hante Meuleman2b76acd2015-10-08 20:33:15 +02002368 err_ptr = brcmf_p2p_create_p2pdev(p2p, NULL, NULL);
2369 if (IS_ERR(err_ptr)) {
2370 brcmf_err("P2P device creation failed.\n");
2371 err = PTR_ERR(err_ptr);
2372 }
Hante Meulemanae7c03f2015-09-18 22:08:08 +02002373 } else {
Hante Meulemanae7c03f2015-09-18 22:08:08 +02002374 p2p->p2pdev_dynamically = true;
2375 }
Arend van Spriel55479df2015-06-11 00:12:22 +02002376 return err;
2377}
2378
2379/**
2380 * brcmf_p2p_detach() - detach P2P.
2381 *
2382 * @p2p: P2P specific data.
2383 */
2384void brcmf_p2p_detach(struct brcmf_p2p_info *p2p)
2385{
2386 struct brcmf_cfg80211_vif *vif;
2387
2388 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
2389 if (vif != NULL) {
2390 brcmf_p2p_cancel_remain_on_channel(vif->ifp);
2391 brcmf_p2p_deinit_discovery(p2p);
Hante Meuleman9831bcb2015-09-18 22:08:12 +02002392 brcmf_remove_interface(vif->ifp);
Arend van Spriel55479df2015-06-11 00:12:22 +02002393 }
2394 /* just set it all to zero */
2395 memset(p2p, 0, sizeof(*p2p));
2396}
2397