blob: 167b7afdf0d8cdb18739718ff0c59ea373eaa63a [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 Spriel9f440b72013-02-08 15:53:36 +010019#include <net/cfg80211.h>
20
21#include <brcmu_wifi.h>
22#include <brcmu_utils.h>
23#include <defs.h>
24#include <dhd.h>
25#include <dhd_dbg.h>
26#include "fwil.h"
Arend van Sprield3c0b632013-02-08 15:53:37 +010027#include "fwil_types.h"
Arend van Spriel9f440b72013-02-08 15:53:36 +010028#include "p2p.h"
29#include "wl_cfg80211.h"
30
31/* parameters used for p2p escan */
32#define P2PAPI_SCAN_NPROBES 1
33#define P2PAPI_SCAN_DWELL_TIME_MS 80
34#define P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS 40
35#define P2PAPI_SCAN_HOME_TIME_MS 60
36#define P2PAPI_SCAN_NPROBS_TIME_MS 30
37#define P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS 100
38#define WL_SCAN_CONNECT_DWELL_TIME_MS 200
39#define WL_SCAN_JOIN_PROBE_INTERVAL_MS 20
40
41#define BRCMF_P2P_WILDCARD_SSID "DIRECT-"
42#define BRCMF_P2P_WILDCARD_SSID_LEN (sizeof(BRCMF_P2P_WILDCARD_SSID) - 1)
43
44#define SOCIAL_CHAN_1 1
45#define SOCIAL_CHAN_2 6
46#define SOCIAL_CHAN_3 11
Hante Meuleman6eda4e22013-02-08 15:54:02 +010047#define IS_P2P_SOCIAL_CHANNEL(channel) ((channel == SOCIAL_CHAN_1) || \
48 (channel == SOCIAL_CHAN_2) || \
49 (channel == SOCIAL_CHAN_3))
Hante Meuleman15a953d2013-05-27 21:09:54 +020050#define BRCMF_P2P_TEMP_CHAN SOCIAL_CHAN_3
Arend van Spriel9f440b72013-02-08 15:53:36 +010051#define SOCIAL_CHAN_CNT 3
52#define AF_PEER_SEARCH_CNT 2
53
Arend van Sprield3c0b632013-02-08 15:53:37 +010054#define BRCMF_SCB_TIMEOUT_VALUE 20
55
Hante Meulemane6da3402013-02-08 15:53:48 +010056#define P2P_VER 9 /* P2P version: 9=WiFi P2P v1.0 */
57#define P2P_PUB_AF_CATEGORY 0x04
58#define P2P_PUB_AF_ACTION 0x09
59#define P2P_AF_CATEGORY 0x7f
60#define P2P_OUI "\x50\x6F\x9A" /* P2P OUI */
61#define P2P_OUI_LEN 3 /* P2P OUI length */
62
Hante Meuleman18e2f612013-02-08 15:53:49 +010063/* Action Frame Constants */
64#define DOT11_ACTION_HDR_LEN 2 /* action frame category + action */
65#define DOT11_ACTION_CAT_OFF 0 /* category offset */
66#define DOT11_ACTION_ACT_OFF 1 /* action offset */
67
68#define P2P_AF_DWELL_TIME 200
69#define P2P_AF_MIN_DWELL_TIME 100
70#define P2P_AF_MED_DWELL_TIME 400
71#define P2P_AF_LONG_DWELL_TIME 1000
Hante Meuleman6eda4e22013-02-08 15:54:02 +010072#define P2P_AF_TX_MAX_RETRY 1
Hante Meuleman18e2f612013-02-08 15:53:49 +010073#define P2P_AF_MAX_WAIT_TIME 2000
74#define P2P_INVALID_CHANNEL -1
75#define P2P_CHANNEL_SYNC_RETRY 5
76#define P2P_AF_FRM_SCAN_MAX_WAIT 1500
Hante Meuleman6eda4e22013-02-08 15:54:02 +010077#define P2P_DEFAULT_SLEEP_TIME_VSDB 200
Hante Meuleman18e2f612013-02-08 15:53:49 +010078
Hante Meulemane6da3402013-02-08 15:53:48 +010079/* WiFi P2P Public Action Frame OUI Subtypes */
80#define P2P_PAF_GON_REQ 0 /* Group Owner Negotiation Req */
81#define P2P_PAF_GON_RSP 1 /* Group Owner Negotiation Rsp */
82#define P2P_PAF_GON_CONF 2 /* Group Owner Negotiation Confirm */
83#define P2P_PAF_INVITE_REQ 3 /* P2P Invitation Request */
84#define P2P_PAF_INVITE_RSP 4 /* P2P Invitation Response */
85#define P2P_PAF_DEVDIS_REQ 5 /* Device Discoverability Request */
86#define P2P_PAF_DEVDIS_RSP 6 /* Device Discoverability Response */
87#define P2P_PAF_PROVDIS_REQ 7 /* Provision Discovery Request */
88#define P2P_PAF_PROVDIS_RSP 8 /* Provision Discovery Response */
89#define P2P_PAF_SUBTYPE_INVALID 255 /* Invalid Subtype */
90
91/* WiFi P2P Action Frame OUI Subtypes */
92#define P2P_AF_NOTICE_OF_ABSENCE 0 /* Notice of Absence */
93#define P2P_AF_PRESENCE_REQ 1 /* P2P Presence Request */
94#define P2P_AF_PRESENCE_RSP 2 /* P2P Presence Response */
95#define P2P_AF_GO_DISC_REQ 3 /* GO Discoverability Request */
96
97/* P2P Service Discovery related */
98#define P2PSD_ACTION_CATEGORY 0x04 /* Public action frame */
99#define P2PSD_ACTION_ID_GAS_IREQ 0x0a /* GAS Initial Request AF */
100#define P2PSD_ACTION_ID_GAS_IRESP 0x0b /* GAS Initial Response AF */
101#define P2PSD_ACTION_ID_GAS_CREQ 0x0c /* GAS Comback Request AF */
102#define P2PSD_ACTION_ID_GAS_CRESP 0x0d /* GAS Comback Response AF */
103
Arend van Spriel9f440b72013-02-08 15:53:36 +0100104/**
105 * struct brcmf_p2p_disc_st_le - set discovery state in firmware.
106 *
107 * @state: requested discovery state (see enum brcmf_p2p_disc_state).
108 * @chspec: channel parameter for %WL_P2P_DISC_ST_LISTEN state.
109 * @dwell: dwell time in ms for %WL_P2P_DISC_ST_LISTEN state.
110 */
111struct brcmf_p2p_disc_st_le {
112 u8 state;
113 __le16 chspec;
114 __le16 dwell;
115};
116
117/**
118 * enum brcmf_p2p_disc_state - P2P discovery state values
119 *
120 * @WL_P2P_DISC_ST_SCAN: P2P discovery with wildcard SSID and P2P IE.
121 * @WL_P2P_DISC_ST_LISTEN: P2P discovery off-channel for specified time.
122 * @WL_P2P_DISC_ST_SEARCH: P2P discovery with P2P wildcard SSID and P2P IE.
123 */
124enum brcmf_p2p_disc_state {
125 WL_P2P_DISC_ST_SCAN,
126 WL_P2P_DISC_ST_LISTEN,
127 WL_P2P_DISC_ST_SEARCH
128};
129
130/**
131 * struct brcmf_p2p_scan_le - P2P specific scan request.
132 *
133 * @type: type of scan method requested (values: 'E' or 'S').
134 * @reserved: reserved (ignored).
135 * @eparams: parameters used for type 'E'.
136 * @sparams: parameters used for type 'S'.
137 */
138struct brcmf_p2p_scan_le {
139 u8 type;
140 u8 reserved[3];
141 union {
142 struct brcmf_escan_params_le eparams;
143 struct brcmf_scan_params_le sparams;
144 };
145};
146
Arend van Spriel9f440b72013-02-08 15:53:36 +0100147/**
Hante Meulemane6da3402013-02-08 15:53:48 +0100148 * struct brcmf_p2p_pub_act_frame - WiFi P2P Public Action Frame
149 *
150 * @category: P2P_PUB_AF_CATEGORY
151 * @action: P2P_PUB_AF_ACTION
152 * @oui[3]: P2P_OUI
153 * @oui_type: OUI type - P2P_VER
154 * @subtype: OUI subtype - P2P_TYPE_*
155 * @dialog_token: nonzero, identifies req/rsp transaction
156 * @elts[1]: Variable length information elements.
157 */
158struct brcmf_p2p_pub_act_frame {
159 u8 category;
160 u8 action;
161 u8 oui[3];
162 u8 oui_type;
163 u8 subtype;
164 u8 dialog_token;
165 u8 elts[1];
166};
167
168/**
169 * struct brcmf_p2p_action_frame - WiFi P2P Action Frame
170 *
171 * @category: P2P_AF_CATEGORY
172 * @OUI[3]: OUI - P2P_OUI
173 * @type: OUI Type - P2P_VER
174 * @subtype: OUI Subtype - P2P_AF_*
175 * @dialog_token: nonzero, identifies req/resp tranaction
176 * @elts[1]: Variable length information elements.
177 */
178struct brcmf_p2p_action_frame {
179 u8 category;
180 u8 oui[3];
181 u8 type;
182 u8 subtype;
183 u8 dialog_token;
184 u8 elts[1];
185};
186
187/**
188 * struct brcmf_p2psd_gas_pub_act_frame - Wi-Fi GAS Public Action Frame
189 *
190 * @category: 0x04 Public Action Frame
191 * @action: 0x6c Advertisement Protocol
192 * @dialog_token: nonzero, identifies req/rsp transaction
193 * @query_data[1]: Query Data. SD gas ireq SD gas iresp
194 */
195struct brcmf_p2psd_gas_pub_act_frame {
196 u8 category;
197 u8 action;
198 u8 dialog_token;
199 u8 query_data[1];
200};
201
Hante Meuleman18e2f612013-02-08 15:53:49 +0100202/**
203 * struct brcmf_config_af_params - Action Frame Parameters for tx.
204 *
Hante Meuleman18e2f612013-02-08 15:53:49 +0100205 * @mpc_onoff: To make sure to send successfully action frame, we have to
206 * turn off mpc 0: off, 1: on, (-1): do nothing
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100207 * @search_channel: 1: search peer's channel to send af
208 * extra_listen: keep the dwell time to get af response frame.
Hante Meuleman18e2f612013-02-08 15:53:49 +0100209 */
210struct brcmf_config_af_params {
Hante Meuleman18e2f612013-02-08 15:53:49 +0100211 s32 mpc_onoff;
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100212 bool search_channel;
213 bool extra_listen;
Hante Meuleman18e2f612013-02-08 15:53:49 +0100214};
Hante Meulemane6da3402013-02-08 15:53:48 +0100215
216/**
217 * brcmf_p2p_is_pub_action() - true if p2p public type frame.
218 *
219 * @frame: action frame data.
220 * @frame_len: length of action frame data.
221 *
222 * Determine if action frame is p2p public action type
223 */
224static bool brcmf_p2p_is_pub_action(void *frame, u32 frame_len)
225{
226 struct brcmf_p2p_pub_act_frame *pact_frm;
227
228 if (frame == NULL)
229 return false;
230
231 pact_frm = (struct brcmf_p2p_pub_act_frame *)frame;
232 if (frame_len < sizeof(struct brcmf_p2p_pub_act_frame) - 1)
233 return false;
234
235 if (pact_frm->category == P2P_PUB_AF_CATEGORY &&
236 pact_frm->action == P2P_PUB_AF_ACTION &&
237 pact_frm->oui_type == P2P_VER &&
238 memcmp(pact_frm->oui, P2P_OUI, P2P_OUI_LEN) == 0)
239 return true;
240
241 return false;
242}
243
244/**
245 * brcmf_p2p_is_p2p_action() - true if p2p action type frame.
246 *
247 * @frame: action frame data.
248 * @frame_len: length of action frame data.
249 *
250 * Determine if action frame is p2p action type
251 */
252static bool brcmf_p2p_is_p2p_action(void *frame, u32 frame_len)
253{
254 struct brcmf_p2p_action_frame *act_frm;
255
256 if (frame == NULL)
257 return false;
258
259 act_frm = (struct brcmf_p2p_action_frame *)frame;
260 if (frame_len < sizeof(struct brcmf_p2p_action_frame) - 1)
261 return false;
262
263 if (act_frm->category == P2P_AF_CATEGORY &&
264 act_frm->type == P2P_VER &&
265 memcmp(act_frm->oui, P2P_OUI, P2P_OUI_LEN) == 0)
266 return true;
267
268 return false;
269}
270
271/**
272 * brcmf_p2p_is_gas_action() - true if p2p gas action type frame.
273 *
274 * @frame: action frame data.
275 * @frame_len: length of action frame data.
276 *
277 * Determine if action frame is p2p gas action type
278 */
279static bool brcmf_p2p_is_gas_action(void *frame, u32 frame_len)
280{
281 struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm;
282
283 if (frame == NULL)
284 return false;
285
286 sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame;
287 if (frame_len < sizeof(struct brcmf_p2psd_gas_pub_act_frame) - 1)
288 return false;
289
290 if (sd_act_frm->category != P2PSD_ACTION_CATEGORY)
291 return false;
292
293 if (sd_act_frm->action == P2PSD_ACTION_ID_GAS_IREQ ||
294 sd_act_frm->action == P2PSD_ACTION_ID_GAS_IRESP ||
295 sd_act_frm->action == P2PSD_ACTION_ID_GAS_CREQ ||
296 sd_act_frm->action == P2PSD_ACTION_ID_GAS_CRESP)
297 return true;
298
299 return false;
300}
301
302/**
303 * brcmf_p2p_print_actframe() - debug print routine.
304 *
305 * @tx: Received or to be transmitted
306 * @frame: action frame data.
307 * @frame_len: length of action frame data.
308 *
309 * Print information about the p2p action frame
310 */
Hante Meuleman0a4cf482013-02-08 15:53:54 +0100311
312#ifdef DEBUG
313
Hante Meulemane6da3402013-02-08 15:53:48 +0100314static void brcmf_p2p_print_actframe(bool tx, void *frame, u32 frame_len)
315{
316 struct brcmf_p2p_pub_act_frame *pact_frm;
317 struct brcmf_p2p_action_frame *act_frm;
318 struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm;
319
320 if (!frame || frame_len <= 2)
321 return;
322
323 if (brcmf_p2p_is_pub_action(frame, frame_len)) {
324 pact_frm = (struct brcmf_p2p_pub_act_frame *)frame;
325 switch (pact_frm->subtype) {
326 case P2P_PAF_GON_REQ:
327 brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Req Frame\n",
328 (tx) ? "TX" : "RX");
329 break;
330 case P2P_PAF_GON_RSP:
331 brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Rsp Frame\n",
332 (tx) ? "TX" : "RX");
333 break;
334 case P2P_PAF_GON_CONF:
335 brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Confirm Frame\n",
336 (tx) ? "TX" : "RX");
337 break;
338 case P2P_PAF_INVITE_REQ:
339 brcmf_dbg(TRACE, "%s P2P Invitation Request Frame\n",
340 (tx) ? "TX" : "RX");
341 break;
342 case P2P_PAF_INVITE_RSP:
343 brcmf_dbg(TRACE, "%s P2P Invitation Response Frame\n",
344 (tx) ? "TX" : "RX");
345 break;
346 case P2P_PAF_DEVDIS_REQ:
347 brcmf_dbg(TRACE, "%s P2P Device Discoverability Request Frame\n",
348 (tx) ? "TX" : "RX");
349 break;
350 case P2P_PAF_DEVDIS_RSP:
351 brcmf_dbg(TRACE, "%s P2P Device Discoverability Response Frame\n",
352 (tx) ? "TX" : "RX");
353 break;
354 case P2P_PAF_PROVDIS_REQ:
355 brcmf_dbg(TRACE, "%s P2P Provision Discovery Request Frame\n",
356 (tx) ? "TX" : "RX");
357 break;
358 case P2P_PAF_PROVDIS_RSP:
359 brcmf_dbg(TRACE, "%s P2P Provision Discovery Response Frame\n",
360 (tx) ? "TX" : "RX");
361 break;
362 default:
363 brcmf_dbg(TRACE, "%s Unknown P2P Public Action Frame\n",
364 (tx) ? "TX" : "RX");
365 break;
366 }
367 } else if (brcmf_p2p_is_p2p_action(frame, frame_len)) {
368 act_frm = (struct brcmf_p2p_action_frame *)frame;
369 switch (act_frm->subtype) {
370 case P2P_AF_NOTICE_OF_ABSENCE:
371 brcmf_dbg(TRACE, "%s P2P Notice of Absence Frame\n",
372 (tx) ? "TX" : "RX");
373 break;
374 case P2P_AF_PRESENCE_REQ:
375 brcmf_dbg(TRACE, "%s P2P Presence Request Frame\n",
376 (tx) ? "TX" : "RX");
377 break;
378 case P2P_AF_PRESENCE_RSP:
379 brcmf_dbg(TRACE, "%s P2P Presence Response Frame\n",
380 (tx) ? "TX" : "RX");
381 break;
382 case P2P_AF_GO_DISC_REQ:
383 brcmf_dbg(TRACE, "%s P2P Discoverability Request Frame\n",
384 (tx) ? "TX" : "RX");
385 break;
386 default:
387 brcmf_dbg(TRACE, "%s Unknown P2P Action Frame\n",
388 (tx) ? "TX" : "RX");
389 }
390
391 } else if (brcmf_p2p_is_gas_action(frame, frame_len)) {
392 sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame;
393 switch (sd_act_frm->action) {
394 case P2PSD_ACTION_ID_GAS_IREQ:
395 brcmf_dbg(TRACE, "%s P2P GAS Initial Request\n",
396 (tx) ? "TX" : "RX");
397 break;
398 case P2PSD_ACTION_ID_GAS_IRESP:
399 brcmf_dbg(TRACE, "%s P2P GAS Initial Response\n",
400 (tx) ? "TX" : "RX");
401 break;
402 case P2PSD_ACTION_ID_GAS_CREQ:
403 brcmf_dbg(TRACE, "%s P2P GAS Comback Request\n",
404 (tx) ? "TX" : "RX");
405 break;
406 case P2PSD_ACTION_ID_GAS_CRESP:
407 brcmf_dbg(TRACE, "%s P2P GAS Comback Response\n",
408 (tx) ? "TX" : "RX");
409 break;
410 default:
411 brcmf_dbg(TRACE, "%s Unknown P2P GAS Frame\n",
412 (tx) ? "TX" : "RX");
413 break;
414 }
415 }
416}
417
Hante Meuleman0a4cf482013-02-08 15:53:54 +0100418#else
419
420static void brcmf_p2p_print_actframe(bool tx, void *frame, u32 frame_len)
421{
422}
423
424#endif
425
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100426
427/**
Arend van Spriel9f440b72013-02-08 15:53:36 +0100428 * brcmf_p2p_set_firmware() - prepare firmware for peer-to-peer operation.
429 *
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100430 * @ifp: ifp to use for iovars (primary).
431 * @p2p_mac: mac address to configure for p2p_da_override
Arend van Spriel9f440b72013-02-08 15:53:36 +0100432 */
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100433static int brcmf_p2p_set_firmware(struct brcmf_if *ifp, u8 *p2p_mac)
Arend van Spriel9f440b72013-02-08 15:53:36 +0100434{
Arend van Spriel9f440b72013-02-08 15:53:36 +0100435 s32 ret = 0;
436
Arend van Spriel27f10e32013-04-05 10:57:50 +0200437 brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100438 brcmf_fil_iovar_int_set(ifp, "apsta", 1);
Arend van Spriel27f10e32013-04-05 10:57:50 +0200439 brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100440
441 /* In case of COB type, firmware has default mac address
442 * After Initializing firmware, we have to set current mac address to
443 * firmware for P2P device address
444 */
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100445 ret = brcmf_fil_iovar_data_set(ifp, "p2p_da_override", p2p_mac,
446 ETH_ALEN);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100447 if (ret)
448 brcmf_err("failed to update device address ret %d\n", ret);
449
450 return ret;
451}
452
453/**
454 * brcmf_p2p_generate_bss_mac() - derive mac addresses for P2P.
455 *
456 * @p2p: P2P specific data.
Arend van Spriel27f10e32013-04-05 10:57:50 +0200457 * @dev_addr: optional device address.
Arend van Spriel9f440b72013-02-08 15:53:36 +0100458 *
Arend van Spriel27f10e32013-04-05 10:57:50 +0200459 * P2P needs mac addresses for P2P device and interface. If no device
460 * address it specified, these are derived from the primary net device, ie.
461 * the permanent ethernet address of the device.
Arend van Spriel9f440b72013-02-08 15:53:36 +0100462 */
Arend van Spriel27f10e32013-04-05 10:57:50 +0200463static void brcmf_p2p_generate_bss_mac(struct brcmf_p2p_info *p2p, u8 *dev_addr)
Arend van Spriel9f440b72013-02-08 15:53:36 +0100464{
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100465 struct brcmf_if *pri_ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
Arend van Spriel27f10e32013-04-05 10:57:50 +0200466 bool local_admin = false;
467
468 if (!dev_addr || is_zero_ether_addr(dev_addr)) {
469 dev_addr = pri_ifp->mac_addr;
470 local_admin = true;
471 }
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100472
Arend van Spriel9f440b72013-02-08 15:53:36 +0100473 /* Generate the P2P Device Address. This consists of the device's
474 * primary MAC address with the locally administered bit set.
475 */
Arend van Spriel27f10e32013-04-05 10:57:50 +0200476 memcpy(p2p->dev_addr, dev_addr, ETH_ALEN);
477 if (local_admin)
478 p2p->dev_addr[0] |= 0x02;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100479
480 /* Generate the P2P Interface Address. If the discovery and connection
481 * BSSCFGs need to simultaneously co-exist, then this address must be
482 * different from the P2P Device Address, but also locally administered.
483 */
484 memcpy(p2p->int_addr, p2p->dev_addr, ETH_ALEN);
Arend van Spriel27f10e32013-04-05 10:57:50 +0200485 p2p->int_addr[0] |= 0x02;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100486 p2p->int_addr[4] ^= 0x80;
487}
488
489/**
490 * brcmf_p2p_scan_is_p2p_request() - is cfg80211 scan request a P2P scan.
491 *
492 * @request: the scan request as received from cfg80211.
493 *
494 * returns true if one of the ssids in the request matches the
495 * P2P wildcard ssid; otherwise returns false.
496 */
497static bool brcmf_p2p_scan_is_p2p_request(struct cfg80211_scan_request *request)
498{
499 struct cfg80211_ssid *ssids = request->ssids;
500 int i;
501
502 for (i = 0; i < request->n_ssids; i++) {
503 if (ssids[i].ssid_len != BRCMF_P2P_WILDCARD_SSID_LEN)
504 continue;
505
506 brcmf_dbg(INFO, "comparing ssid \"%s\"", ssids[i].ssid);
507 if (!memcmp(BRCMF_P2P_WILDCARD_SSID, ssids[i].ssid,
508 BRCMF_P2P_WILDCARD_SSID_LEN))
509 return true;
510 }
511 return false;
512}
513
514/**
515 * brcmf_p2p_set_discover_state - set discover state in firmware.
516 *
517 * @ifp: low-level interface object.
518 * @state: discover state to set.
519 * @chanspec: channel parameters (for state @WL_P2P_DISC_ST_LISTEN only).
520 * @listen_ms: duration to listen (for state @WL_P2P_DISC_ST_LISTEN only).
521 */
522static s32 brcmf_p2p_set_discover_state(struct brcmf_if *ifp, u8 state,
523 u16 chanspec, u16 listen_ms)
524{
525 struct brcmf_p2p_disc_st_le discover_state;
526 s32 ret = 0;
527 brcmf_dbg(TRACE, "enter\n");
528
529 discover_state.state = state;
530 discover_state.chspec = cpu_to_le16(chanspec);
531 discover_state.dwell = cpu_to_le16(listen_ms);
532 ret = brcmf_fil_bsscfg_data_set(ifp, "p2p_state", &discover_state,
533 sizeof(discover_state));
534 return ret;
535}
536
537/**
Arend van Spriel9f440b72013-02-08 15:53:36 +0100538 * brcmf_p2p_deinit_discovery() - disable P2P device discovery.
539 *
540 * @p2p: P2P specific data.
541 *
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100542 * Resets the discovery state and disables it in firmware.
Arend van Spriel9f440b72013-02-08 15:53:36 +0100543 */
544static s32 brcmf_p2p_deinit_discovery(struct brcmf_p2p_info *p2p)
545{
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100546 struct brcmf_cfg80211_vif *vif;
547
Arend van Spriel9f440b72013-02-08 15:53:36 +0100548 brcmf_dbg(TRACE, "enter\n");
549
Arend van Spriel9f440b72013-02-08 15:53:36 +0100550 /* Set the discovery state to SCAN */
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100551 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
552 (void)brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100553
554 /* Disable P2P discovery in the firmware */
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100555 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
556 (void)brcmf_fil_iovar_int_set(vif->ifp, "p2p_disc", 0);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100557
558 return 0;
559}
560
561/**
562 * brcmf_p2p_enable_discovery() - initialize and configure discovery.
563 *
564 * @p2p: P2P specific data.
Arend van Spriel9f440b72013-02-08 15:53:36 +0100565 *
566 * Initializes the discovery device and configure the virtual interface.
567 */
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100568static int brcmf_p2p_enable_discovery(struct brcmf_p2p_info *p2p)
Arend van Spriel9f440b72013-02-08 15:53:36 +0100569{
570 struct brcmf_cfg80211_vif *vif;
571 s32 ret = 0;
572
573 brcmf_dbg(TRACE, "enter\n");
574 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100575 if (!vif) {
576 brcmf_err("P2P config device not available\n");
577 ret = -EPERM;
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100578 goto exit;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100579 }
580
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100581 if (test_bit(BRCMF_P2P_STATUS_ENABLED, &p2p->status)) {
582 brcmf_dbg(INFO, "P2P config device already configured\n");
583 goto exit;
584 }
585
586 /* Re-initialize P2P Discovery in the firmware */
587 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
588 ret = brcmf_fil_iovar_int_set(vif->ifp, "p2p_disc", 1);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100589 if (ret < 0) {
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100590 brcmf_err("set p2p_disc error\n");
Arend van Spriel9f440b72013-02-08 15:53:36 +0100591 goto exit;
592 }
Arend van Spriel9f440b72013-02-08 15:53:36 +0100593 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100594 ret = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
595 if (ret < 0) {
596 brcmf_err("unable to set WL_P2P_DISC_ST_SCAN\n");
597 goto exit;
598 }
Arend van Spriel9f440b72013-02-08 15:53:36 +0100599
600 /*
601 * Set wsec to any non-zero value in the discovery bsscfg
602 * to ensure our P2P probe responses have the privacy bit
603 * set in the 802.11 WPA IE. Some peer devices may not
604 * initiate WPS with us if this bit is not set.
605 */
606 ret = brcmf_fil_bsscfg_int_set(vif->ifp, "wsec", AES_ENABLED);
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100607 if (ret < 0) {
Arend van Spriel9f440b72013-02-08 15:53:36 +0100608 brcmf_err("wsec error %d\n", ret);
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100609 goto exit;
610 }
Arend van Spriel9f440b72013-02-08 15:53:36 +0100611
Hante Meuleman2fde59d2013-02-08 15:53:52 +0100612 set_bit(BRCMF_P2P_STATUS_ENABLED, &p2p->status);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100613exit:
614 return ret;
615}
616
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100617/**
Arend van Spriel9f440b72013-02-08 15:53:36 +0100618 * brcmf_p2p_escan() - initiate a P2P scan.
619 *
620 * @p2p: P2P specific data.
621 * @num_chans: number of channels to scan.
622 * @chanspecs: channel parameters for @num_chans channels.
623 * @search_state: P2P discover state to use.
624 * @action: scan action to pass to firmware.
625 * @bss_type: type of P2P bss.
626 */
627static s32 brcmf_p2p_escan(struct brcmf_p2p_info *p2p, u32 num_chans,
628 u16 chanspecs[], s32 search_state, u16 action,
629 enum p2p_bss_type bss_type)
630{
631 s32 ret = 0;
632 s32 memsize = offsetof(struct brcmf_p2p_scan_le,
633 eparams.params_le.channel_list);
634 s32 nprobes;
635 s32 active;
636 u32 i;
637 u8 *memblk;
638 struct brcmf_cfg80211_vif *vif;
639 struct brcmf_p2p_scan_le *p2p_params;
640 struct brcmf_scan_params_le *sparams;
641 struct brcmf_ssid ssid;
642
Arend van Spriel9f440b72013-02-08 15:53:36 +0100643 memsize += num_chans * sizeof(__le16);
644 memblk = kzalloc(memsize, GFP_KERNEL);
645 if (!memblk)
646 return -ENOMEM;
647
648 vif = p2p->bss_idx[bss_type].vif;
649 if (vif == NULL) {
650 brcmf_err("no vif for bss type %d\n", bss_type);
651 ret = -EINVAL;
652 goto exit;
653 }
654
655 switch (search_state) {
656 case WL_P2P_DISC_ST_SEARCH:
657 /*
658 * If we in SEARCH STATE, we don't need to set SSID explictly
659 * because dongle use P2P WILDCARD internally by default
660 */
661 /* use null ssid */
662 ssid.SSID_len = 0;
663 memset(ssid.SSID, 0, sizeof(ssid.SSID));
664 break;
665 case WL_P2P_DISC_ST_SCAN:
666 /*
667 * wpa_supplicant has p2p_find command with type social or
668 * progressive. For progressive, we need to set the ssid to
669 * P2P WILDCARD because we just do broadcast scan unless
670 * setting SSID.
671 */
672 ssid.SSID_len = BRCMF_P2P_WILDCARD_SSID_LEN;
673 memcpy(ssid.SSID, BRCMF_P2P_WILDCARD_SSID, ssid.SSID_len);
674 break;
675 default:
676 brcmf_err(" invalid search state %d\n", search_state);
677 ret = -EINVAL;
678 goto exit;
679 }
680
681 brcmf_p2p_set_discover_state(vif->ifp, search_state, 0, 0);
682
683 /*
684 * set p2p scan parameters.
685 */
686 p2p_params = (struct brcmf_p2p_scan_le *)memblk;
687 p2p_params->type = 'E';
688
689 /* determine the scan engine parameters */
690 sparams = &p2p_params->eparams.params_le;
691 sparams->bss_type = DOT11_BSSTYPE_ANY;
692 if (p2p->cfg->active_scan)
693 sparams->scan_type = 0;
694 else
695 sparams->scan_type = 1;
696
697 memset(&sparams->bssid, 0xFF, ETH_ALEN);
698 if (ssid.SSID_len)
699 memcpy(sparams->ssid_le.SSID, ssid.SSID, ssid.SSID_len);
700 sparams->ssid_le.SSID_len = cpu_to_le32(ssid.SSID_len);
701 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;
711 else if (wl_get_vif_state_all(p2p->cfg, BRCMF_VIF_STATUS_CONNECTED))
712 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");
800 } else if (dev != NULL && vif->mode == WL_MODE_AP) {
801 /* If you are already a GO, then do SEARCH only */
802 brcmf_dbg(INFO, "Already a GO. Do SEARCH Only\n");
803 search_state = WL_P2P_DISC_ST_SEARCH;
804 } else {
805 brcmf_dbg(INFO, "P2P SCAN STATE START\n");
806 }
807
808 /*
809 * no P2P scanning on passive or DFS channels.
810 */
811 for (i = 0; i < request->n_channels; i++) {
812 struct ieee80211_channel *chan = request->channels[i];
813
814 if (chan->flags & (IEEE80211_CHAN_RADAR |
815 IEEE80211_CHAN_PASSIVE_SCAN))
816 continue;
817
Franky Lin83cf17a2013-04-11 13:28:50 +0200818 chanspecs[i] = channel_to_chanspec(&p2p->cfg->d11inf,
819 chan);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100820 brcmf_dbg(INFO, "%d: chan=%d, channel spec=%x\n",
821 num_nodfs, chan->hw_value, chanspecs[i]);
822 num_nodfs++;
823 }
824 err = brcmf_p2p_escan(p2p, num_nodfs, chanspecs, search_state,
825 action, P2PAPI_BSSCFG_DEVICE);
826 }
827exit:
828 if (err)
829 brcmf_err("error (%d)\n", err);
830 return err;
831}
832
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100833
834/**
835 * brcmf_p2p_find_listen_channel() - find listen channel in ie string.
836 *
837 * @ie: string of information elements.
838 * @ie_len: length of string.
839 *
840 * Scan ie for p2p ie and look for attribute 6 channel. If available determine
841 * channel and return it.
842 */
843static s32 brcmf_p2p_find_listen_channel(const u8 *ie, u32 ie_len)
844{
845 u8 channel_ie[5];
846 s32 listen_channel;
847 s32 err;
848
849 err = cfg80211_get_p2p_attr(ie, ie_len,
850 IEEE80211_P2P_ATTR_LISTEN_CHANNEL,
851 channel_ie, sizeof(channel_ie));
852 if (err < 0)
853 return err;
854
855 /* listen channel subel length format: */
856 /* 3(country) + 1(op. class) + 1(chan num) */
857 listen_channel = (s32)channel_ie[3 + 1];
858
859 if (listen_channel == SOCIAL_CHAN_1 ||
860 listen_channel == SOCIAL_CHAN_2 ||
861 listen_channel == SOCIAL_CHAN_3) {
862 brcmf_dbg(INFO, "Found my Listen Channel %d\n", listen_channel);
863 return listen_channel;
864 }
865
866 return -EPERM;
867}
868
869
Arend van Spriel9f440b72013-02-08 15:53:36 +0100870/**
871 * brcmf_p2p_scan_prep() - prepare scan based on request.
872 *
873 * @wiphy: wiphy device.
874 * @request: scan request from cfg80211.
Hante Meuleman0f8ffe12013-02-08 15:53:42 +0100875 * @vif: vif on which scan request is to be executed.
Arend van Spriel9f440b72013-02-08 15:53:36 +0100876 *
877 * Prepare the scan appropriately for type of scan requested. Overrides the
878 * escan .run() callback for peer-to-peer scanning.
879 */
880int brcmf_p2p_scan_prep(struct wiphy *wiphy,
Hante Meuleman0f8ffe12013-02-08 15:53:42 +0100881 struct cfg80211_scan_request *request,
882 struct brcmf_cfg80211_vif *vif)
Arend van Spriel9f440b72013-02-08 15:53:36 +0100883{
884 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
885 struct brcmf_p2p_info *p2p = &cfg->p2p;
886 int err = 0;
887
888 if (brcmf_p2p_scan_is_p2p_request(request)) {
889 /* find my listen channel */
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100890 err = brcmf_p2p_find_listen_channel(request->ie,
891 request->ie_len);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100892 if (err < 0)
893 return err;
894
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100895 p2p->afx_hdl.my_listen_chan = err;
896
Arend van Spriel9f440b72013-02-08 15:53:36 +0100897 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
898 brcmf_dbg(INFO, "P2P: GO_NEG_PHASE status cleared\n");
899
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100900 err = brcmf_p2p_enable_discovery(p2p);
Hante Meuleman0f8ffe12013-02-08 15:53:42 +0100901 if (err)
902 return err;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100903
Hante Meuleman0f8ffe12013-02-08 15:53:42 +0100904 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
905
906 /* override .run_escan() callback. */
Arend van Spriel9f440b72013-02-08 15:53:36 +0100907 cfg->escan_info.run = brcmf_p2p_run_escan;
Arend van Spriel9f440b72013-02-08 15:53:36 +0100908 }
Hante Meuleman0f8ffe12013-02-08 15:53:42 +0100909 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBREQ_FLAG,
910 request->ie, request->ie_len);
Arend van Spriel9f440b72013-02-08 15:53:36 +0100911 return err;
912}
913
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100914
915/**
Hante Meulemanf2058dd2013-02-08 15:53:50 +0100916 * brcmf_p2p_discover_listen() - set firmware to discover listen state.
917 *
918 * @p2p: p2p device.
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100919 * @channel: channel nr for discover listen.
920 * @duration: time in ms to stay on channel.
Hante Meulemanf2058dd2013-02-08 15:53:50 +0100921 *
922 */
923static s32
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100924brcmf_p2p_discover_listen(struct brcmf_p2p_info *p2p, u16 channel, u32 duration)
Hante Meulemanf2058dd2013-02-08 15:53:50 +0100925{
926 struct brcmf_cfg80211_vif *vif;
Franky Lin83cf17a2013-04-11 13:28:50 +0200927 struct brcmu_chan ch;
Hante Meulemanf2058dd2013-02-08 15:53:50 +0100928 s32 err = 0;
Hante Meulemanf2058dd2013-02-08 15:53:50 +0100929
930 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
931 if (!vif) {
932 brcmf_err("Discovery is not set, so we have nothing to do\n");
933 err = -EPERM;
934 goto exit;
935 }
936
937 if (test_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status)) {
938 brcmf_err("Previous LISTEN is not completed yet\n");
939 /* WAR: prevent cookie mismatch in wpa_supplicant return OK */
940 goto exit;
941 }
942
Franky Lin83cf17a2013-04-11 13:28:50 +0200943 ch.chnum = channel;
944 ch.bw = BRCMU_CHAN_BW_20;
945 p2p->cfg->d11inf.encchspec(&ch);
Hante Meulemanf2058dd2013-02-08 15:53:50 +0100946 err = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_LISTEN,
Franky Lin83cf17a2013-04-11 13:28:50 +0200947 ch.chspec, (u16)duration);
Hante Meulemanf2058dd2013-02-08 15:53:50 +0100948 if (!err) {
949 set_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status);
950 p2p->remain_on_channel_cookie++;
951 }
952exit:
953 return err;
954}
955
956
957/**
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100958 * brcmf_p2p_remain_on_channel() - put device on channel and stay there.
959 *
960 * @wiphy: wiphy device.
961 * @channel: channel to stay on.
962 * @duration: time in ms to remain on channel.
963 *
964 */
965int brcmf_p2p_remain_on_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
966 struct ieee80211_channel *channel,
967 unsigned int duration, u64 *cookie)
968{
969 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
970 struct brcmf_p2p_info *p2p = &cfg->p2p;
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100971 s32 err;
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100972 u16 channel_nr;
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100973
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100974 channel_nr = ieee80211_frequency_to_channel(channel->center_freq);
975 brcmf_dbg(TRACE, "Enter, channel: %d, duration ms (%d)\n", channel_nr,
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100976 duration);
977
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100978 err = brcmf_p2p_enable_discovery(p2p);
979 if (err)
980 goto exit;
Hante Meuleman6eda4e22013-02-08 15:54:02 +0100981 err = brcmf_p2p_discover_listen(p2p, channel_nr, duration);
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100982 if (err)
983 goto exit;
984
Hante Meulemanf2058dd2013-02-08 15:53:50 +0100985 memcpy(&p2p->remain_on_channel, channel, sizeof(*channel));
986 *cookie = p2p->remain_on_channel_cookie;
Arend van Spriel1ce30862013-02-08 15:53:51 +0100987 cfg80211_ready_on_channel(wdev, *cookie, channel, duration, GFP_KERNEL);
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100988
989exit:
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100990 return err;
991}
992
993
994/**
995 * brcmf_p2p_notify_listen_complete() - p2p listen has completed.
996 *
997 * @ifp: interfac control.
998 * @e: event message. Not used, to make it usable for fweh event dispatcher.
999 * @data: payload of message. Not used.
1000 *
1001 */
1002int brcmf_p2p_notify_listen_complete(struct brcmf_if *ifp,
1003 const struct brcmf_event_msg *e,
1004 void *data)
1005{
1006 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
1007 struct brcmf_p2p_info *p2p = &cfg->p2p;
1008
1009 brcmf_dbg(TRACE, "Enter\n");
Hante Meulemanf2058dd2013-02-08 15:53:50 +01001010 if (test_and_clear_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN,
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001011 &p2p->status)) {
1012 if (test_and_clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN,
1013 &p2p->status)) {
1014 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME,
1015 &p2p->status);
1016 brcmf_dbg(INFO, "Listen DONE, wake up wait_next_af\n");
1017 complete(&p2p->wait_next_af);
1018 }
1019
Hante Meulemanf2058dd2013-02-08 15:53:50 +01001020 cfg80211_remain_on_channel_expired(&ifp->vif->wdev,
1021 p2p->remain_on_channel_cookie,
Hante Meuleman0de8aac2013-02-08 15:53:38 +01001022 &p2p->remain_on_channel,
1023 GFP_KERNEL);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001024 }
Hante Meuleman0de8aac2013-02-08 15:53:38 +01001025 return 0;
1026}
1027
1028
1029/**
1030 * brcmf_p2p_cancel_remain_on_channel() - cancel p2p listen state.
1031 *
1032 * @ifp: interfac control.
1033 *
1034 */
1035void brcmf_p2p_cancel_remain_on_channel(struct brcmf_if *ifp)
1036{
1037 if (!ifp)
1038 return;
1039 brcmf_p2p_set_discover_state(ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
1040 brcmf_p2p_notify_listen_complete(ifp, NULL, NULL);
1041}
1042
1043
Arend van Spriel9f440b72013-02-08 15:53:36 +01001044/**
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001045 * brcmf_p2p_act_frm_search() - search function for action frame.
1046 *
1047 * @p2p: p2p device.
1048 * channel: channel on which action frame is to be trasmitted.
1049 *
1050 * search function to reach at common channel to send action frame. When
1051 * channel is 0 then all social channels will be used to send af
1052 */
1053static s32 brcmf_p2p_act_frm_search(struct brcmf_p2p_info *p2p, u16 channel)
1054{
1055 s32 err;
1056 u32 channel_cnt;
1057 u16 *default_chan_list;
1058 u32 i;
Franky Lin83cf17a2013-04-11 13:28:50 +02001059 struct brcmu_chan ch;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001060
1061 brcmf_dbg(TRACE, "Enter\n");
1062
1063 if (channel)
1064 channel_cnt = AF_PEER_SEARCH_CNT;
1065 else
1066 channel_cnt = SOCIAL_CHAN_CNT;
1067 default_chan_list = kzalloc(channel_cnt * sizeof(*default_chan_list),
1068 GFP_KERNEL);
1069 if (default_chan_list == NULL) {
1070 brcmf_err("channel list allocation failed\n");
1071 err = -ENOMEM;
1072 goto exit;
1073 }
Franky Lin83cf17a2013-04-11 13:28:50 +02001074 ch.bw = BRCMU_CHAN_BW_20;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001075 if (channel) {
Franky Lin83cf17a2013-04-11 13:28:50 +02001076 ch.chnum = channel;
1077 p2p->cfg->d11inf.encchspec(&ch);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001078 /* insert same channel to the chan_list */
1079 for (i = 0; i < channel_cnt; i++)
Franky Lin83cf17a2013-04-11 13:28:50 +02001080 default_chan_list[i] = ch.chspec;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001081 } else {
Franky Lin83cf17a2013-04-11 13:28:50 +02001082 ch.chnum = SOCIAL_CHAN_1;
1083 p2p->cfg->d11inf.encchspec(&ch);
1084 default_chan_list[0] = ch.chspec;
1085 ch.chnum = SOCIAL_CHAN_2;
1086 p2p->cfg->d11inf.encchspec(&ch);
1087 default_chan_list[1] = ch.chspec;
1088 ch.chnum = SOCIAL_CHAN_3;
1089 p2p->cfg->d11inf.encchspec(&ch);
1090 default_chan_list[2] = ch.chspec;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001091 }
1092 err = brcmf_p2p_escan(p2p, channel_cnt, default_chan_list,
1093 WL_P2P_DISC_ST_SEARCH, WL_ESCAN_ACTION_START,
1094 P2PAPI_BSSCFG_DEVICE);
1095 kfree(default_chan_list);
1096exit:
1097 return err;
1098}
1099
1100
1101/**
1102 * brcmf_p2p_afx_handler() - afx worker thread.
1103 *
1104 * @work:
1105 *
1106 */
1107static void brcmf_p2p_afx_handler(struct work_struct *work)
1108{
1109 struct afx_hdl *afx_hdl = container_of(work, struct afx_hdl, afx_work);
1110 struct brcmf_p2p_info *p2p = container_of(afx_hdl,
1111 struct brcmf_p2p_info,
1112 afx_hdl);
1113 s32 err;
1114
1115 if (!afx_hdl->is_active)
1116 return;
1117
1118 if (afx_hdl->is_listen && afx_hdl->my_listen_chan)
1119 /* 100ms ~ 300ms */
1120 err = brcmf_p2p_discover_listen(p2p, afx_hdl->my_listen_chan,
Akinobu Mitae00adf32013-05-07 16:18:15 -07001121 100 * (1 + prandom_u32() % 3));
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001122 else
1123 err = brcmf_p2p_act_frm_search(p2p, afx_hdl->peer_listen_chan);
1124
1125 if (err) {
1126 brcmf_err("ERROR occurred! value is (%d)\n", err);
1127 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
1128 &p2p->status))
1129 complete(&afx_hdl->act_frm_scan);
1130 }
1131}
1132
1133
1134/**
1135 * brcmf_p2p_af_searching_channel() - search channel.
1136 *
1137 * @p2p: p2p device info struct.
1138 *
1139 */
1140static s32 brcmf_p2p_af_searching_channel(struct brcmf_p2p_info *p2p)
1141{
1142 struct afx_hdl *afx_hdl = &p2p->afx_hdl;
1143 struct brcmf_cfg80211_vif *pri_vif;
1144 unsigned long duration;
1145 s32 retry;
1146
1147 brcmf_dbg(TRACE, "Enter\n");
1148
1149 pri_vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
1150
1151 INIT_COMPLETION(afx_hdl->act_frm_scan);
1152 set_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status);
1153 afx_hdl->is_active = true;
1154 afx_hdl->peer_chan = P2P_INVALID_CHANNEL;
1155
1156 /* Loop to wait until we find a peer's channel or the
1157 * pending action frame tx is cancelled.
1158 */
1159 retry = 0;
1160 duration = msecs_to_jiffies(P2P_AF_FRM_SCAN_MAX_WAIT);
1161 while ((retry < P2P_CHANNEL_SYNC_RETRY) &&
1162 (afx_hdl->peer_chan == P2P_INVALID_CHANNEL)) {
1163 afx_hdl->is_listen = false;
1164 brcmf_dbg(TRACE, "Scheduling action frame for sending.. (%d)\n",
1165 retry);
1166 /* search peer on peer's listen channel */
1167 schedule_work(&afx_hdl->afx_work);
1168 wait_for_completion_timeout(&afx_hdl->act_frm_scan, duration);
1169 if ((afx_hdl->peer_chan != P2P_INVALID_CHANNEL) ||
1170 (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
1171 &p2p->status)))
1172 break;
1173
1174 if (afx_hdl->my_listen_chan) {
1175 brcmf_dbg(TRACE, "Scheduling listen peer, channel=%d\n",
1176 afx_hdl->my_listen_chan);
1177 /* listen on my listen channel */
1178 afx_hdl->is_listen = true;
1179 schedule_work(&afx_hdl->afx_work);
1180 wait_for_completion_timeout(&afx_hdl->act_frm_scan,
1181 duration);
1182 }
1183 if ((afx_hdl->peer_chan != P2P_INVALID_CHANNEL) ||
1184 (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
1185 &p2p->status)))
1186 break;
1187 retry++;
1188
1189 /* if sta is connected or connecting, sleep for a while before
1190 * retry af tx or finding a peer
1191 */
1192 if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &pri_vif->sme_state) ||
1193 test_bit(BRCMF_VIF_STATUS_CONNECTING, &pri_vif->sme_state))
1194 msleep(P2P_DEFAULT_SLEEP_TIME_VSDB);
1195 }
1196
1197 brcmf_dbg(TRACE, "Completed search/listen peer_chan=%d\n",
1198 afx_hdl->peer_chan);
1199 afx_hdl->is_active = false;
1200
1201 clear_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status);
1202
1203 return afx_hdl->peer_chan;
1204}
1205
1206
1207/**
1208 * brcmf_p2p_scan_finding_common_channel() - was escan used for finding channel
1209 *
1210 * @cfg: common configuration struct.
1211 * @bi: bss info struct, result from scan.
1212 *
1213 */
1214bool brcmf_p2p_scan_finding_common_channel(struct brcmf_cfg80211_info *cfg,
1215 struct brcmf_bss_info_le *bi)
1216
1217{
1218 struct brcmf_p2p_info *p2p = &cfg->p2p;
1219 struct afx_hdl *afx_hdl = &p2p->afx_hdl;
Franky Lin83cf17a2013-04-11 13:28:50 +02001220 struct brcmu_chan ch;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001221 u8 *ie;
1222 s32 err;
1223 u8 p2p_dev_addr[ETH_ALEN];
1224
1225 if (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status))
1226 return false;
1227
1228 if (bi == NULL) {
1229 brcmf_dbg(TRACE, "ACTION FRAME SCAN Done\n");
1230 if (afx_hdl->peer_chan == P2P_INVALID_CHANNEL)
1231 complete(&afx_hdl->act_frm_scan);
1232 return true;
1233 }
1234
1235 ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset);
1236 memset(p2p_dev_addr, 0, sizeof(p2p_dev_addr));
1237 err = cfg80211_get_p2p_attr(ie, le32_to_cpu(bi->ie_length),
1238 IEEE80211_P2P_ATTR_DEVICE_INFO,
1239 p2p_dev_addr, sizeof(p2p_dev_addr));
1240 if (err < 0)
1241 err = cfg80211_get_p2p_attr(ie, le32_to_cpu(bi->ie_length),
1242 IEEE80211_P2P_ATTR_DEVICE_ID,
1243 p2p_dev_addr, sizeof(p2p_dev_addr));
1244 if ((err >= 0) &&
1245 (!memcmp(p2p_dev_addr, afx_hdl->tx_dst_addr, ETH_ALEN))) {
Franky Lin83cf17a2013-04-11 13:28:50 +02001246 if (!bi->ctl_ch) {
1247 ch.chspec = le16_to_cpu(bi->chanspec);
1248 cfg->d11inf.decchspec(&ch);
1249 bi->ctl_ch = ch.chnum;
1250 }
1251 afx_hdl->peer_chan = bi->ctl_ch;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001252 brcmf_dbg(TRACE, "ACTION FRAME SCAN : Peer %pM found, channel : %d\n",
1253 afx_hdl->tx_dst_addr, afx_hdl->peer_chan);
1254 complete(&afx_hdl->act_frm_scan);
1255 }
1256 return true;
1257}
1258
1259/**
1260 * brcmf_p2p_stop_wait_next_action_frame() - finish scan if af tx complete.
1261 *
1262 * @cfg: common configuration struct.
1263 *
1264 */
1265static void
1266brcmf_p2p_stop_wait_next_action_frame(struct brcmf_cfg80211_info *cfg)
1267{
1268 struct brcmf_p2p_info *p2p = &cfg->p2p;
Arend van Spriela0f472a2013-04-05 10:57:49 +02001269 struct brcmf_if *ifp = cfg->escan_info.ifp;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001270
1271 if (test_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME, &p2p->status) &&
1272 (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status) ||
1273 test_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status))) {
1274 brcmf_dbg(TRACE, "*** Wake UP ** abort actframe iovar\n");
1275 /* if channel is not zero, "actfame" uses off channel scan.
1276 * So abort scan for off channel completion.
1277 */
1278 if (p2p->af_sent_channel)
Arend van Spriela0f472a2013-04-05 10:57:49 +02001279 brcmf_notify_escan_complete(cfg, ifp, true, true);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001280 } else if (test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN,
1281 &p2p->status)) {
1282 brcmf_dbg(TRACE, "*** Wake UP ** abort listen for next af frame\n");
1283 /* So abort scan to cancel listen */
Arend van Spriela0f472a2013-04-05 10:57:49 +02001284 brcmf_notify_escan_complete(cfg, ifp, true, true);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001285 }
1286}
1287
1288
1289/**
1290 * brcmf_p2p_gon_req_collision() - Check if go negotiaton collission
1291 *
1292 * @p2p: p2p device info struct.
1293 *
1294 * return true if recevied action frame is to be dropped.
1295 */
1296static bool
1297brcmf_p2p_gon_req_collision(struct brcmf_p2p_info *p2p, u8 *mac)
1298{
1299 struct brcmf_cfg80211_info *cfg = p2p->cfg;
1300 struct brcmf_if *ifp;
1301
1302 brcmf_dbg(TRACE, "Enter\n");
1303
1304 if (!test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status) ||
1305 !p2p->gon_req_action)
1306 return false;
1307
1308 brcmf_dbg(TRACE, "GO Negotiation Request COLLISION !!!\n");
1309 /* if sa(peer) addr is less than da(my) addr, then this device
1310 * process peer's gon request and block to send gon req.
1311 * if not (sa addr > da addr),
1312 * this device will process gon request and drop gon req of peer.
1313 */
1314 ifp = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif->ifp;
1315 if (memcmp(mac, ifp->mac_addr, ETH_ALEN) < 0) {
1316 brcmf_dbg(INFO, "Block transmit gon req !!!\n");
1317 p2p->block_gon_req_tx = true;
1318 /* if we are finding a common channel for sending af,
1319 * do not scan more to block to send current gon req
1320 */
1321 if (test_and_clear_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
1322 &p2p->status))
1323 complete(&p2p->afx_hdl.act_frm_scan);
1324 if (test_and_clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME,
1325 &p2p->status))
1326 brcmf_p2p_stop_wait_next_action_frame(cfg);
1327 return false;
1328 }
1329
1330 /* drop gon request of peer to process gon request by this device. */
1331 brcmf_dbg(INFO, "Drop received gon req !!!\n");
1332
1333 return true;
1334}
1335
1336
1337/**
Hante Meulemane6da3402013-02-08 15:53:48 +01001338 * brcmf_p2p_notify_action_frame_rx() - received action frame.
1339 *
1340 * @ifp: interfac control.
1341 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1342 * @data: payload of message, containing action frame data.
1343 *
1344 */
1345int brcmf_p2p_notify_action_frame_rx(struct brcmf_if *ifp,
1346 const struct brcmf_event_msg *e,
1347 void *data)
1348{
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001349 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
1350 struct brcmf_p2p_info *p2p = &cfg->p2p;
1351 struct afx_hdl *afx_hdl = &p2p->afx_hdl;
Hante Meulemane6da3402013-02-08 15:53:48 +01001352 struct wireless_dev *wdev;
1353 u32 mgmt_frame_len = e->datalen - sizeof(struct brcmf_rx_mgmt_data);
1354 struct brcmf_rx_mgmt_data *rxframe = (struct brcmf_rx_mgmt_data *)data;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001355 u8 *frame = (u8 *)(rxframe + 1);
1356 struct brcmf_p2p_pub_act_frame *act_frm;
1357 struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm;
Franky Lin83cf17a2013-04-11 13:28:50 +02001358 struct brcmu_chan ch;
Hante Meulemane6da3402013-02-08 15:53:48 +01001359 struct ieee80211_mgmt *mgmt_frame;
Hante Meulemane6da3402013-02-08 15:53:48 +01001360 s32 freq;
1361 u16 mgmt_type;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001362 u8 action;
Hante Meulemane6da3402013-02-08 15:53:48 +01001363
Franky Lin83cf17a2013-04-11 13:28:50 +02001364 ch.chspec = be16_to_cpu(rxframe->chanspec);
1365 cfg->d11inf.decchspec(&ch);
Hante Meulemane6da3402013-02-08 15:53:48 +01001366 /* Check if wpa_supplicant has registered for this frame */
1367 brcmf_dbg(INFO, "ifp->vif->mgmt_rx_reg %04x\n", ifp->vif->mgmt_rx_reg);
1368 mgmt_type = (IEEE80211_STYPE_ACTION & IEEE80211_FCTL_STYPE) >> 4;
1369 if ((ifp->vif->mgmt_rx_reg & BIT(mgmt_type)) == 0)
1370 return 0;
1371
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001372 brcmf_p2p_print_actframe(false, frame, mgmt_frame_len);
1373
1374 action = P2P_PAF_SUBTYPE_INVALID;
1375 if (brcmf_p2p_is_pub_action(frame, mgmt_frame_len)) {
1376 act_frm = (struct brcmf_p2p_pub_act_frame *)frame;
1377 action = act_frm->subtype;
1378 if ((action == P2P_PAF_GON_REQ) &&
1379 (brcmf_p2p_gon_req_collision(p2p, (u8 *)e->addr))) {
1380 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
1381 &p2p->status) &&
1382 (memcmp(afx_hdl->tx_dst_addr, e->addr,
1383 ETH_ALEN) == 0)) {
Franky Lin83cf17a2013-04-11 13:28:50 +02001384 afx_hdl->peer_chan = ch.chnum;
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001385 brcmf_dbg(INFO, "GON request: Peer found, channel=%d\n",
1386 afx_hdl->peer_chan);
1387 complete(&afx_hdl->act_frm_scan);
1388 }
1389 return 0;
1390 }
1391 /* After complete GO Negotiation, roll back to mpc mode */
1392 if ((action == P2P_PAF_GON_CONF) ||
1393 (action == P2P_PAF_PROVDIS_RSP))
Arend van Sprielf96aa072013-04-05 10:57:48 +02001394 brcmf_set_mpc(ifp, 1);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001395 if (action == P2P_PAF_GON_CONF) {
1396 brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status cleared\n");
1397 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
1398 }
1399 } else if (brcmf_p2p_is_gas_action(frame, mgmt_frame_len)) {
1400 sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame;
1401 action = sd_act_frm->action;
1402 }
1403
1404 if (test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status) &&
1405 (p2p->next_af_subtype == action)) {
1406 brcmf_dbg(TRACE, "We got a right next frame! (%d)\n", action);
1407 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME,
1408 &p2p->status);
1409 /* Stop waiting for next AF. */
1410 brcmf_p2p_stop_wait_next_action_frame(cfg);
1411 }
Hante Meulemane6da3402013-02-08 15:53:48 +01001412
1413 mgmt_frame = kzalloc(offsetof(struct ieee80211_mgmt, u) +
1414 mgmt_frame_len, GFP_KERNEL);
1415 if (!mgmt_frame) {
1416 brcmf_err("No memory available for action frame\n");
1417 return -ENOMEM;
1418 }
1419 memcpy(mgmt_frame->da, ifp->mac_addr, ETH_ALEN);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001420 brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSSID, mgmt_frame->bssid,
1421 ETH_ALEN);
Hante Meulemane6da3402013-02-08 15:53:48 +01001422 memcpy(mgmt_frame->sa, e->addr, ETH_ALEN);
1423 mgmt_frame->frame_control = cpu_to_le16(IEEE80211_STYPE_ACTION);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001424 memcpy(&mgmt_frame->u, frame, mgmt_frame_len);
Hante Meulemane6da3402013-02-08 15:53:48 +01001425 mgmt_frame_len += offsetof(struct ieee80211_mgmt, u);
1426
Franky Lin83cf17a2013-04-11 13:28:50 +02001427 freq = ieee80211_channel_to_frequency(ch.chnum,
1428 ch.band == BRCMU_CHAN_BAND_2G ?
Hante Meulemane6da3402013-02-08 15:53:48 +01001429 IEEE80211_BAND_2GHZ :
1430 IEEE80211_BAND_5GHZ);
Arend van Spriel5b57af62013-04-05 10:57:53 +02001431
1432 wdev = &ifp->vif->wdev;
Hante Meulemane6da3402013-02-08 15:53:48 +01001433 cfg80211_rx_mgmt(wdev, freq, 0, (u8 *)mgmt_frame, mgmt_frame_len,
1434 GFP_ATOMIC);
1435
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
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001504 INIT_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) &&
1867 (memcmp(afx_hdl->tx_dst_addr, e->addr, ETH_ALEN) == 0)) {
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
1898 cfg80211_rx_mgmt(&vif->wdev, freq, 0, mgmt_frame, mgmt_frame_len,
1899 GFP_ATOMIC);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001900
1901 brcmf_dbg(INFO, "mgmt_frame_len (%d) , e->datalen (%d), chanspec (%04x), freq (%d)\n",
1902 mgmt_frame_len, e->datalen, chanspec, freq);
1903
1904 return 0;
1905}
1906
Hante Meuleman18e2f612013-02-08 15:53:49 +01001907
1908/**
Arend van Spriel9f440b72013-02-08 15:53:36 +01001909 * brcmf_p2p_attach() - attach for P2P.
1910 *
1911 * @cfg: driver private data for cfg80211 interface.
1912 */
Hante Meuleman2fde59d2013-02-08 15:53:52 +01001913s32 brcmf_p2p_attach(struct brcmf_cfg80211_info *cfg)
Arend van Spriel9f440b72013-02-08 15:53:36 +01001914{
Hante Meuleman2fde59d2013-02-08 15:53:52 +01001915 struct brcmf_if *pri_ifp;
1916 struct brcmf_if *p2p_ifp;
1917 struct brcmf_cfg80211_vif *p2p_vif;
Arend van Spriel9f440b72013-02-08 15:53:36 +01001918 struct brcmf_p2p_info *p2p;
Hante Meuleman2fde59d2013-02-08 15:53:52 +01001919 struct brcmf_pub *drvr;
1920 s32 bssidx;
1921 s32 err = 0;
Arend van Spriel9f440b72013-02-08 15:53:36 +01001922
1923 p2p = &cfg->p2p;
Arend van Spriel9f440b72013-02-08 15:53:36 +01001924 p2p->cfg = cfg;
Hante Meuleman2fde59d2013-02-08 15:53:52 +01001925
1926 drvr = cfg->pub;
1927
1928 pri_ifp = drvr->iflist[0];
1929 p2p_ifp = drvr->iflist[1];
1930
1931 p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif = pri_ifp->vif;
1932
1933 if (p2p_ifp) {
Hante Meulemandded3d52013-02-08 15:53:57 +01001934 p2p_vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_P2P_DEVICE,
Hante Meuleman2fde59d2013-02-08 15:53:52 +01001935 false);
1936 if (IS_ERR(p2p_vif)) {
1937 brcmf_err("could not create discovery vif\n");
1938 err = -ENOMEM;
1939 goto exit;
1940 }
1941
1942 p2p_vif->ifp = p2p_ifp;
1943 p2p_ifp->vif = p2p_vif;
1944 p2p_vif->wdev.netdev = p2p_ifp->ndev;
1945 p2p_ifp->ndev->ieee80211_ptr = &p2p_vif->wdev;
1946 SET_NETDEV_DEV(p2p_ifp->ndev, wiphy_dev(cfg->wiphy));
1947
1948 p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif = p2p_vif;
1949
Arend van Spriel27f10e32013-04-05 10:57:50 +02001950 brcmf_p2p_generate_bss_mac(p2p, NULL);
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02001951 memcpy(p2p_ifp->mac_addr, p2p->dev_addr, ETH_ALEN);
Hante Meuleman2fde59d2013-02-08 15:53:52 +01001952 brcmf_p2p_set_firmware(pri_ifp, p2p->dev_addr);
1953
1954 /* Initialize P2P Discovery in the firmware */
1955 err = brcmf_fil_iovar_int_set(pri_ifp, "p2p_disc", 1);
1956 if (err < 0) {
1957 brcmf_err("set p2p_disc error\n");
Arend van Spriel24e28be2013-05-27 21:09:55 +02001958 brcmf_free_vif(cfg, p2p_vif);
Hante Meuleman2fde59d2013-02-08 15:53:52 +01001959 goto exit;
1960 }
1961 /* obtain bsscfg index for P2P discovery */
1962 err = brcmf_fil_iovar_int_get(pri_ifp, "p2p_dev", &bssidx);
1963 if (err < 0) {
1964 brcmf_err("retrieving discover bsscfg index failed\n");
Arend van Spriel24e28be2013-05-27 21:09:55 +02001965 brcmf_free_vif(cfg, p2p_vif);
Hante Meuleman2fde59d2013-02-08 15:53:52 +01001966 goto exit;
1967 }
1968 /* Verify that firmware uses same bssidx as driver !! */
1969 if (p2p_ifp->bssidx != bssidx) {
1970 brcmf_err("Incorrect bssidx=%d, compared to p2p_ifp->bssidx=%d\n",
1971 bssidx, p2p_ifp->bssidx);
Arend van Spriel24e28be2013-05-27 21:09:55 +02001972 brcmf_free_vif(cfg, p2p_vif);
Hante Meuleman2fde59d2013-02-08 15:53:52 +01001973 goto exit;
1974 }
1975
1976 init_completion(&p2p->send_af_done);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01001977 INIT_WORK(&p2p->afx_hdl.afx_work, brcmf_p2p_afx_handler);
1978 init_completion(&p2p->afx_hdl.act_frm_scan);
1979 init_completion(&p2p->wait_next_af);
Hante Meuleman2fde59d2013-02-08 15:53:52 +01001980 }
1981exit:
1982 return err;
Arend van Spriel9f440b72013-02-08 15:53:36 +01001983}
1984
Hante Meuleman2fde59d2013-02-08 15:53:52 +01001985
Arend van Spriel9f440b72013-02-08 15:53:36 +01001986/**
1987 * brcmf_p2p_detach() - detach P2P.
1988 *
1989 * @p2p: P2P specific data.
1990 */
1991void brcmf_p2p_detach(struct brcmf_p2p_info *p2p)
1992{
Hante Meuleman2fde59d2013-02-08 15:53:52 +01001993 struct brcmf_cfg80211_vif *vif;
1994
1995 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
1996 if (vif != NULL) {
1997 brcmf_p2p_cancel_remain_on_channel(vif->ifp);
Hante Meuleman0de8aac2013-02-08 15:53:38 +01001998 brcmf_p2p_deinit_discovery(p2p);
Hante Meuleman2fde59d2013-02-08 15:53:52 +01001999 /* remove discovery interface */
Arend van Spriel24e28be2013-05-27 21:09:55 +02002000 brcmf_free_vif(p2p->cfg, vif);
Hante Meuleman2fde59d2013-02-08 15:53:52 +01002001 p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif = NULL;
Hante Meuleman0de8aac2013-02-08 15:53:38 +01002002 }
Arend van Spriel9f440b72013-02-08 15:53:36 +01002003 /* just set it all to zero */
2004 memset(p2p, 0, sizeof(*p2p));
2005}
2006
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01002007/**
2008 * brcmf_p2p_get_current_chanspec() - Get current operation channel.
2009 *
2010 * @p2p: P2P specific data.
2011 * @chanspec: chanspec to be returned.
2012 */
2013static void brcmf_p2p_get_current_chanspec(struct brcmf_p2p_info *p2p,
2014 u16 *chanspec)
2015{
2016 struct brcmf_if *ifp;
Hante Meuleman15a953d2013-05-27 21:09:54 +02002017 u8 mac_addr[ETH_ALEN];
Franky Lin83cf17a2013-04-11 13:28:50 +02002018 struct brcmu_chan ch;
Hante Meuleman15a953d2013-05-27 21:09:54 +02002019 struct brcmf_bss_info_le *bi;
2020 u8 *buf;
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01002021
2022 ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
2023
Hante Meuleman15a953d2013-05-27 21:09:54 +02002024 if (brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSSID, mac_addr,
2025 ETH_ALEN) == 0) {
2026 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
2027 if (buf != NULL) {
2028 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
2029 if (brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
2030 buf, WL_BSS_INFO_MAX) == 0) {
2031 bi = (struct brcmf_bss_info_le *)(buf + 4);
2032 *chanspec = le16_to_cpu(bi->chanspec);
2033 kfree(buf);
2034 return;
2035 }
2036 kfree(buf);
2037 }
2038 }
2039 /* Use default channel for P2P */
2040 ch.chnum = BRCMF_P2P_TEMP_CHAN;
Franky Lin83cf17a2013-04-11 13:28:50 +02002041 ch.bw = BRCMU_CHAN_BW_20;
2042 p2p->cfg->d11inf.encchspec(&ch);
2043 *chanspec = ch.chspec;
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01002044}
2045
2046/**
2047 * Change a P2P Role.
2048 * Parameters:
2049 * @mac: MAC address of the BSS to change a role
2050 * Returns 0 if success.
2051 */
2052int brcmf_p2p_ifchange(struct brcmf_cfg80211_info *cfg,
2053 enum brcmf_fil_p2p_if_types if_type)
2054{
2055 struct brcmf_p2p_info *p2p = &cfg->p2p;
2056 struct brcmf_cfg80211_vif *vif;
2057 struct brcmf_fil_p2p_if_le if_request;
2058 s32 err;
2059 u16 chanspec;
2060
2061 brcmf_dbg(TRACE, "Enter\n");
2062
2063 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
2064 if (!vif) {
2065 brcmf_err("vif for P2PAPI_BSSCFG_PRIMARY does not exist\n");
2066 return -EPERM;
2067 }
Arend van Spriela0f472a2013-04-05 10:57:49 +02002068 brcmf_notify_escan_complete(cfg, vif->ifp, true, true);
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01002069 vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
2070 if (!vif) {
2071 brcmf_err("vif for P2PAPI_BSSCFG_CONNECTION does not exist\n");
2072 return -EPERM;
2073 }
Arend van Sprielf96aa072013-04-05 10:57:48 +02002074 brcmf_set_mpc(vif->ifp, 0);
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01002075
2076 /* In concurrency case, STA may be already associated in a particular */
2077 /* channel. so retrieve the current channel of primary interface and */
2078 /* then start the virtual interface on that. */
2079 brcmf_p2p_get_current_chanspec(p2p, &chanspec);
2080
2081 if_request.type = cpu_to_le16((u16)if_type);
2082 if_request.chspec = cpu_to_le16(chanspec);
2083 memcpy(if_request.addr, p2p->int_addr, sizeof(if_request.addr));
2084
2085 brcmf_cfg80211_arm_vif_event(cfg, vif);
2086 err = brcmf_fil_iovar_data_set(vif->ifp, "p2p_ifupd", &if_request,
2087 sizeof(if_request));
2088 if (err) {
2089 brcmf_err("p2p_ifupd FAILED, err=%d\n", err);
2090 brcmf_cfg80211_arm_vif_event(cfg, NULL);
2091 return err;
2092 }
2093 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_CHANGE,
2094 msecs_to_jiffies(1500));
2095 brcmf_cfg80211_arm_vif_event(cfg, NULL);
2096 if (!err) {
2097 brcmf_err("No BRCMF_E_IF_CHANGE event received\n");
2098 return -EIO;
2099 }
2100
2101 err = brcmf_fil_cmd_int_set(vif->ifp, BRCMF_C_SET_SCB_TIMEOUT,
2102 BRCMF_SCB_TIMEOUT_VALUE);
2103
2104 return err;
2105}
2106
2107static int brcmf_p2p_request_p2p_if(struct brcmf_p2p_info *p2p,
2108 struct brcmf_if *ifp, u8 ea[ETH_ALEN],
Arend van Sprield3c0b632013-02-08 15:53:37 +01002109 enum brcmf_fil_p2p_if_types iftype)
2110{
2111 struct brcmf_fil_p2p_if_le if_request;
Arend van Sprield3c0b632013-02-08 15:53:37 +01002112 int err;
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01002113 u16 chanspec;
Arend van Sprield3c0b632013-02-08 15:53:37 +01002114
2115 /* we need a default channel */
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01002116 brcmf_p2p_get_current_chanspec(p2p, &chanspec);
Arend van Sprield3c0b632013-02-08 15:53:37 +01002117
2118 /* fill the firmware request */
2119 memcpy(if_request.addr, ea, ETH_ALEN);
Hante Meuleman7ee2d922013-02-08 15:53:43 +01002120 if_request.type = cpu_to_le16((u16)iftype);
Arend van Sprield3c0b632013-02-08 15:53:37 +01002121 if_request.chspec = cpu_to_le16(chanspec);
2122
2123 err = brcmf_fil_iovar_data_set(ifp, "p2p_ifadd", &if_request,
2124 sizeof(if_request));
2125 if (err)
2126 return err;
2127
Arend van Sprield3c0b632013-02-08 15:53:37 +01002128 return err;
2129}
2130
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01002131static int brcmf_p2p_disable_p2p_if(struct brcmf_cfg80211_vif *vif)
2132{
2133 struct brcmf_cfg80211_info *cfg = wdev_to_cfg(&vif->wdev);
2134 struct net_device *pri_ndev = cfg_to_ndev(cfg);
2135 struct brcmf_if *ifp = netdev_priv(pri_ndev);
2136 u8 *addr = vif->wdev.netdev->dev_addr;
2137
2138 return brcmf_fil_iovar_data_set(ifp, "p2p_ifdis", addr, ETH_ALEN);
2139}
2140
2141static int brcmf_p2p_release_p2p_if(struct brcmf_cfg80211_vif *vif)
2142{
2143 struct brcmf_cfg80211_info *cfg = wdev_to_cfg(&vif->wdev);
2144 struct net_device *pri_ndev = cfg_to_ndev(cfg);
2145 struct brcmf_if *ifp = netdev_priv(pri_ndev);
2146 u8 *addr = vif->wdev.netdev->dev_addr;
2147
2148 return brcmf_fil_iovar_data_set(ifp, "p2p_ifdel", addr, ETH_ALEN);
2149}
2150
Arend van Spriel9f440b72013-02-08 15:53:36 +01002151/**
Arend van Spriel27f10e32013-04-05 10:57:50 +02002152 * brcmf_p2p_create_p2pdev() - create a P2P_DEVICE virtual interface.
2153 *
2154 * @p2p: P2P specific data.
2155 * @wiphy: wiphy device of new interface.
2156 * @addr: mac address for this new interface.
2157 */
2158static struct wireless_dev *brcmf_p2p_create_p2pdev(struct brcmf_p2p_info *p2p,
2159 struct wiphy *wiphy,
2160 u8 *addr)
2161{
2162 struct brcmf_cfg80211_vif *p2p_vif;
2163 struct brcmf_if *p2p_ifp;
2164 struct brcmf_if *pri_ifp;
2165 int err;
2166 u32 bssidx;
2167
2168 if (p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
2169 return ERR_PTR(-ENOSPC);
2170
2171 p2p_vif = brcmf_alloc_vif(p2p->cfg, NL80211_IFTYPE_P2P_DEVICE,
2172 false);
2173 if (IS_ERR(p2p_vif)) {
2174 brcmf_err("could not create discovery vif\n");
2175 return (struct wireless_dev *)p2p_vif;
2176 }
2177
Arend van Spriel27f10e32013-04-05 10:57:50 +02002178 pri_ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02002179 brcmf_p2p_generate_bss_mac(p2p, addr);
Arend van Spriel27f10e32013-04-05 10:57:50 +02002180 brcmf_p2p_set_firmware(pri_ifp, p2p->dev_addr);
2181
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02002182 brcmf_cfg80211_arm_vif_event(p2p->cfg, p2p_vif);
2183
Arend van Spriel27f10e32013-04-05 10:57:50 +02002184 /* Initialize P2P Discovery in the firmware */
2185 err = brcmf_fil_iovar_int_set(pri_ifp, "p2p_disc", 1);
2186 if (err < 0) {
2187 brcmf_err("set p2p_disc error\n");
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02002188 brcmf_cfg80211_arm_vif_event(p2p->cfg, NULL);
2189 goto fail;
Arend van Spriel27f10e32013-04-05 10:57:50 +02002190 }
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02002191
2192 /* wait for firmware event */
2193 err = brcmf_cfg80211_wait_vif_event_timeout(p2p->cfg, BRCMF_E_IF_ADD,
2194 msecs_to_jiffies(1500));
2195 brcmf_cfg80211_arm_vif_event(p2p->cfg, NULL);
2196 if (!err) {
2197 brcmf_err("timeout occurred\n");
2198 err = -EIO;
2199 goto fail;
2200 }
2201
2202 /* discovery interface created */
2203 p2p_ifp = p2p_vif->ifp;
2204 p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif = p2p_vif;
2205 memcpy(p2p_ifp->mac_addr, p2p->dev_addr, ETH_ALEN);
2206 memcpy(&p2p_vif->wdev.address, p2p->dev_addr, sizeof(p2p->dev_addr));
2207
2208 /* verify bsscfg index for P2P discovery */
Arend van Spriel27f10e32013-04-05 10:57:50 +02002209 err = brcmf_fil_iovar_int_get(pri_ifp, "p2p_dev", &bssidx);
2210 if (err < 0) {
2211 brcmf_err("retrieving discover bsscfg index failed\n");
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02002212 goto fail;
Arend van Spriel27f10e32013-04-05 10:57:50 +02002213 }
2214
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02002215 WARN_ON(p2p_ifp->bssidx != bssidx);
Arend van Spriel27f10e32013-04-05 10:57:50 +02002216
2217 init_completion(&p2p->send_af_done);
2218 INIT_WORK(&p2p->afx_hdl.afx_work, brcmf_p2p_afx_handler);
2219 init_completion(&p2p->afx_hdl.act_frm_scan);
2220 init_completion(&p2p->wait_next_af);
2221
2222 return &p2p_vif->wdev;
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02002223
2224fail:
Arend van Spriel24e28be2013-05-27 21:09:55 +02002225 brcmf_free_vif(p2p->cfg, p2p_vif);
Arend van Spriel01b8e7d2013-04-05 10:57:51 +02002226 return ERR_PTR(err);
Arend van Spriel27f10e32013-04-05 10:57:50 +02002227}
2228
2229/**
2230 * brcmf_p2p_delete_p2pdev() - delete P2P_DEVICE virtual interface.
2231 *
2232 * @vif: virtual interface object to delete.
2233 */
Arend van Spriel24e28be2013-05-27 21:09:55 +02002234static void brcmf_p2p_delete_p2pdev(struct brcmf_cfg80211_info *cfg,
2235 struct brcmf_cfg80211_vif *vif)
Arend van Spriel27f10e32013-04-05 10:57:50 +02002236{
Arend van Spriel27f10e32013-04-05 10:57:50 +02002237 cfg80211_unregister_wdev(&vif->wdev);
Arend van Spriel24e28be2013-05-27 21:09:55 +02002238 cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif = NULL;
2239 brcmf_free_vif(cfg, vif);
Arend van Spriel27f10e32013-04-05 10:57:50 +02002240}
2241
2242/**
Arend van Spriel9f440b72013-02-08 15:53:36 +01002243 * brcmf_p2p_add_vif() - create a new P2P virtual interface.
2244 *
2245 * @wiphy: wiphy device of new interface.
2246 * @name: name of the new interface.
2247 * @type: nl80211 interface type.
Arend van Spriel27f10e32013-04-05 10:57:50 +02002248 * @flags: not used.
2249 * @params: contains mac address for P2P device.
Arend van Spriel9f440b72013-02-08 15:53:36 +01002250 */
2251struct wireless_dev *brcmf_p2p_add_vif(struct wiphy *wiphy, const char *name,
2252 enum nl80211_iftype type, u32 *flags,
2253 struct vif_params *params)
2254{
Arend van Sprield3c0b632013-02-08 15:53:37 +01002255 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2256 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
2257 struct brcmf_cfg80211_vif *vif;
2258 enum brcmf_fil_p2p_if_types iftype;
2259 enum wl_mode mode;
2260 int err;
2261
2262 if (brcmf_cfg80211_vif_event_armed(cfg))
2263 return ERR_PTR(-EBUSY);
2264
Arend van Spriel9f440b72013-02-08 15:53:36 +01002265 brcmf_dbg(INFO, "adding vif \"%s\" (type=%d)\n", name, type);
Arend van Sprield3c0b632013-02-08 15:53:37 +01002266
2267 switch (type) {
2268 case NL80211_IFTYPE_P2P_CLIENT:
2269 iftype = BRCMF_FIL_P2P_IF_CLIENT;
2270 mode = WL_MODE_BSS;
2271 break;
2272 case NL80211_IFTYPE_P2P_GO:
2273 iftype = BRCMF_FIL_P2P_IF_GO;
2274 mode = WL_MODE_AP;
2275 break;
Arend van Spriel27f10e32013-04-05 10:57:50 +02002276 case NL80211_IFTYPE_P2P_DEVICE:
2277 return brcmf_p2p_create_p2pdev(&cfg->p2p, wiphy,
2278 params->macaddr);
Arend van Sprield3c0b632013-02-08 15:53:37 +01002279 default:
2280 return ERR_PTR(-EOPNOTSUPP);
2281 }
2282
2283 vif = brcmf_alloc_vif(cfg, type, false);
Hante Meuleman7ee2d922013-02-08 15:53:43 +01002284 if (IS_ERR(vif))
2285 return (struct wireless_dev *)vif;
Arend van Sprield3c0b632013-02-08 15:53:37 +01002286 brcmf_cfg80211_arm_vif_event(cfg, vif);
2287
Hante Meuleman7a5c1f62013-02-08 15:53:44 +01002288 err = brcmf_p2p_request_p2p_if(&cfg->p2p, ifp, cfg->p2p.int_addr,
2289 iftype);
Hante Meuleman7ee2d922013-02-08 15:53:43 +01002290 if (err) {
2291 brcmf_cfg80211_arm_vif_event(cfg, NULL);
Arend van Sprield3c0b632013-02-08 15:53:37 +01002292 goto fail;
Hante Meuleman7ee2d922013-02-08 15:53:43 +01002293 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01002294
2295 /* wait for firmware event */
2296 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_ADD,
2297 msecs_to_jiffies(1500));
2298 brcmf_cfg80211_arm_vif_event(cfg, NULL);
2299 if (!err) {
2300 brcmf_err("timeout occurred\n");
2301 err = -EIO;
2302 goto fail;
2303 }
2304
2305 /* interface created in firmware */
2306 ifp = vif->ifp;
2307 if (!ifp) {
2308 brcmf_err("no if pointer provided\n");
2309 err = -ENOENT;
Hante Meuleman7ee2d922013-02-08 15:53:43 +01002310 goto fail;
Arend van Sprield3c0b632013-02-08 15:53:37 +01002311 }
2312
2313 strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1);
Hante Meuleman4b3a89d2013-02-08 15:54:01 +01002314 err = brcmf_net_attach(ifp, true);
2315 if (err) {
2316 brcmf_err("Registering netdevice failed\n");
2317 goto fail;
2318 }
Hante Meuleman7ee2d922013-02-08 15:53:43 +01002319 cfg->p2p.bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = vif;
2320 /* Disable firmware roaming for P2P interface */
2321 brcmf_fil_iovar_int_set(ifp, "roam_off", 1);
2322 if (iftype == BRCMF_FIL_P2P_IF_GO) {
2323 /* set station timeout for p2p */
2324 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCB_TIMEOUT,
2325 BRCMF_SCB_TIMEOUT_VALUE);
2326 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01002327 return &ifp->vif->wdev;
2328
2329fail:
Arend van Spriel24e28be2013-05-27 21:09:55 +02002330 brcmf_free_vif(cfg, vif);
Arend van Sprield3c0b632013-02-08 15:53:37 +01002331 return ERR_PTR(err);
Arend van Spriel9f440b72013-02-08 15:53:36 +01002332}
2333
2334/**
2335 * brcmf_p2p_del_vif() - delete a P2P virtual interface.
2336 *
2337 * @wiphy: wiphy device of interface.
2338 * @wdev: wireless device of interface.
2339 *
2340 * TODO: not yet supported.
2341 */
2342int brcmf_p2p_del_vif(struct wiphy *wiphy, struct wireless_dev *wdev)
2343{
Arend van Sprield3c0b632013-02-08 15:53:37 +01002344 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01002345 struct brcmf_p2p_info *p2p = &cfg->p2p;
Arend van Spriel9f440b72013-02-08 15:53:36 +01002346 struct brcmf_cfg80211_vif *vif;
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01002347 unsigned long jiffie_timeout = msecs_to_jiffies(1500);
2348 bool wait_for_disable = false;
Arend van Sprield3c0b632013-02-08 15:53:37 +01002349 int err;
Arend van Spriel9f440b72013-02-08 15:53:36 +01002350
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01002351 brcmf_dbg(TRACE, "delete P2P vif\n");
Arend van Spriel9f440b72013-02-08 15:53:36 +01002352 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
Arend van Sprield3c0b632013-02-08 15:53:37 +01002353
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01002354 switch (vif->wdev.iftype) {
2355 case NL80211_IFTYPE_P2P_CLIENT:
2356 if (test_bit(BRCMF_VIF_STATUS_DISCONNECTING, &vif->sme_state))
2357 wait_for_disable = true;
2358 break;
2359
2360 case NL80211_IFTYPE_P2P_GO:
2361 if (!brcmf_p2p_disable_p2p_if(vif))
2362 wait_for_disable = true;
2363 break;
2364
2365 case NL80211_IFTYPE_P2P_DEVICE:
Arend van Spriel24e28be2013-05-27 21:09:55 +02002366 brcmf_p2p_delete_p2pdev(cfg, vif);
Arend van Spriel27f10e32013-04-05 10:57:50 +02002367 return 0;
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01002368 default:
2369 return -ENOTSUPP;
2370 break;
2371 }
2372
Hante Meuleman6eda4e22013-02-08 15:54:02 +01002373 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
2374 brcmf_dbg(INFO, "P2P: GO_NEG_PHASE status cleared\n");
2375
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01002376 if (wait_for_disable)
Hante Meuleman7ee2d922013-02-08 15:53:43 +01002377 wait_for_completion_timeout(&cfg->vif_disabled,
2378 msecs_to_jiffies(500));
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01002379
2380 brcmf_vif_clear_mgmt_ies(vif);
Arend van Sprield3c0b632013-02-08 15:53:37 +01002381
2382 brcmf_cfg80211_arm_vif_event(cfg, vif);
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01002383 err = brcmf_p2p_release_p2p_if(vif);
Hante Meuleman7ee2d922013-02-08 15:53:43 +01002384 if (!err) {
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01002385 /* wait for firmware event */
2386 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_DEL,
2387 jiffie_timeout);
Hante Meuleman7ee2d922013-02-08 15:53:43 +01002388 if (!err)
2389 err = -EIO;
2390 else
2391 err = 0;
2392 }
Arend van Sprield3c0b632013-02-08 15:53:37 +01002393 brcmf_cfg80211_arm_vif_event(cfg, NULL);
Arend van Spriel24e28be2013-05-27 21:09:55 +02002394 brcmf_free_vif(cfg, vif);
Hante Meuleman6eda4e22013-02-08 15:54:02 +01002395 p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = NULL;
Arend van Spriel5f4f9f12013-02-08 15:53:41 +01002396
2397 return err;
Arend van Spriel9f440b72013-02-08 15:53:36 +01002398}
Arend van Spriel27f10e32013-04-05 10:57:50 +02002399
2400int brcmf_p2p_start_device(struct wiphy *wiphy, struct wireless_dev *wdev)
2401{
2402 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2403 struct brcmf_p2p_info *p2p = &cfg->p2p;
2404 struct brcmf_cfg80211_vif *vif;
2405 int err;
2406
2407 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
2408 mutex_lock(&cfg->usr_sync);
2409 err = brcmf_p2p_enable_discovery(p2p);
2410 if (!err)
2411 set_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state);
2412 mutex_unlock(&cfg->usr_sync);
2413 return err;
2414}
2415
2416void brcmf_p2p_stop_device(struct wiphy *wiphy, struct wireless_dev *wdev)
2417{
2418 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2419 struct brcmf_p2p_info *p2p = &cfg->p2p;
2420 struct brcmf_cfg80211_vif *vif;
2421
2422 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
2423 mutex_lock(&cfg->usr_sync);
2424 (void)brcmf_p2p_deinit_discovery(p2p);
2425 brcmf_abort_scanning(cfg);
2426 clear_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state);
2427 mutex_unlock(&cfg->usr_sync);
2428}