2 * Copyright (c) 2012 Broadcom Corporation
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.
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.
16 #include <linux/slab.h>
17 #include <linux/netdevice.h>
18 #include <net/cfg80211.h>
20 #include <brcmu_wifi.h>
21 #include <brcmu_utils.h>
26 #include "fwil_types.h"
28 #include "wl_cfg80211.h"
30 /* parameters used for p2p escan */
31 #define P2PAPI_SCAN_NPROBES 1
32 #define P2PAPI_SCAN_DWELL_TIME_MS 80
33 #define P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS 40
34 #define P2PAPI_SCAN_HOME_TIME_MS 60
35 #define P2PAPI_SCAN_NPROBS_TIME_MS 30
36 #define P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS 100
37 #define WL_SCAN_CONNECT_DWELL_TIME_MS 200
38 #define WL_SCAN_JOIN_PROBE_INTERVAL_MS 20
40 #define BRCMF_P2P_WILDCARD_SSID "DIRECT-"
41 #define BRCMF_P2P_WILDCARD_SSID_LEN (sizeof(BRCMF_P2P_WILDCARD_SSID) - 1)
43 #define SOCIAL_CHAN_1 1
44 #define SOCIAL_CHAN_2 6
45 #define SOCIAL_CHAN_3 11
46 #define SOCIAL_CHAN_CNT 3
47 #define AF_PEER_SEARCH_CNT 2
49 #define BRCMF_SCB_TIMEOUT_VALUE 20
51 #define P2P_VER 9 /* P2P version: 9=WiFi P2P v1.0 */
52 #define P2P_PUB_AF_CATEGORY 0x04
53 #define P2P_PUB_AF_ACTION 0x09
54 #define P2P_AF_CATEGORY 0x7f
55 #define P2P_OUI "\x50\x6F\x9A" /* P2P OUI */
56 #define P2P_OUI_LEN 3 /* P2P OUI length */
58 /* Action Frame Constants */
59 #define DOT11_ACTION_HDR_LEN 2 /* action frame category + action */
60 #define DOT11_ACTION_CAT_OFF 0 /* category offset */
61 #define DOT11_ACTION_ACT_OFF 1 /* action offset */
63 #define P2P_AF_DWELL_TIME 200
64 #define P2P_AF_MIN_DWELL_TIME 100
65 #define P2P_AF_MED_DWELL_TIME 400
66 #define P2P_AF_LONG_DWELL_TIME 1000
67 #define P2P_AF_TX_MAX_RETRY 5
68 #define P2P_AF_MAX_WAIT_TIME 2000
69 #define P2P_INVALID_CHANNEL -1
70 #define P2P_CHANNEL_SYNC_RETRY 5
71 #define P2P_AF_FRM_SCAN_MAX_WAIT 1500
73 /* WiFi P2P Public Action Frame OUI Subtypes */
74 #define P2P_PAF_GON_REQ 0 /* Group Owner Negotiation Req */
75 #define P2P_PAF_GON_RSP 1 /* Group Owner Negotiation Rsp */
76 #define P2P_PAF_GON_CONF 2 /* Group Owner Negotiation Confirm */
77 #define P2P_PAF_INVITE_REQ 3 /* P2P Invitation Request */
78 #define P2P_PAF_INVITE_RSP 4 /* P2P Invitation Response */
79 #define P2P_PAF_DEVDIS_REQ 5 /* Device Discoverability Request */
80 #define P2P_PAF_DEVDIS_RSP 6 /* Device Discoverability Response */
81 #define P2P_PAF_PROVDIS_REQ 7 /* Provision Discovery Request */
82 #define P2P_PAF_PROVDIS_RSP 8 /* Provision Discovery Response */
83 #define P2P_PAF_SUBTYPE_INVALID 255 /* Invalid Subtype */
85 /* WiFi P2P Action Frame OUI Subtypes */
86 #define P2P_AF_NOTICE_OF_ABSENCE 0 /* Notice of Absence */
87 #define P2P_AF_PRESENCE_REQ 1 /* P2P Presence Request */
88 #define P2P_AF_PRESENCE_RSP 2 /* P2P Presence Response */
89 #define P2P_AF_GO_DISC_REQ 3 /* GO Discoverability Request */
91 /* P2P Service Discovery related */
92 #define P2PSD_ACTION_CATEGORY 0x04 /* Public action frame */
93 #define P2PSD_ACTION_ID_GAS_IREQ 0x0a /* GAS Initial Request AF */
94 #define P2PSD_ACTION_ID_GAS_IRESP 0x0b /* GAS Initial Response AF */
95 #define P2PSD_ACTION_ID_GAS_CREQ 0x0c /* GAS Comback Request AF */
96 #define P2PSD_ACTION_ID_GAS_CRESP 0x0d /* GAS Comback Response AF */
99 * struct brcmf_p2p_disc_st_le - set discovery state in firmware.
101 * @state: requested discovery state (see enum brcmf_p2p_disc_state).
102 * @chspec: channel parameter for %WL_P2P_DISC_ST_LISTEN state.
103 * @dwell: dwell time in ms for %WL_P2P_DISC_ST_LISTEN state.
105 struct brcmf_p2p_disc_st_le {
112 * enum brcmf_p2p_disc_state - P2P discovery state values
114 * @WL_P2P_DISC_ST_SCAN: P2P discovery with wildcard SSID and P2P IE.
115 * @WL_P2P_DISC_ST_LISTEN: P2P discovery off-channel for specified time.
116 * @WL_P2P_DISC_ST_SEARCH: P2P discovery with P2P wildcard SSID and P2P IE.
118 enum brcmf_p2p_disc_state {
120 WL_P2P_DISC_ST_LISTEN,
121 WL_P2P_DISC_ST_SEARCH
125 * struct brcmf_p2p_scan_le - P2P specific scan request.
127 * @type: type of scan method requested (values: 'E' or 'S').
128 * @reserved: reserved (ignored).
129 * @eparams: parameters used for type 'E'.
130 * @sparams: parameters used for type 'S'.
132 struct brcmf_p2p_scan_le {
136 struct brcmf_escan_params_le eparams;
137 struct brcmf_scan_params_le sparams;
142 * struct brcmf_p2p_pub_act_frame - WiFi P2P Public Action Frame
144 * @category: P2P_PUB_AF_CATEGORY
145 * @action: P2P_PUB_AF_ACTION
147 * @oui_type: OUI type - P2P_VER
148 * @subtype: OUI subtype - P2P_TYPE_*
149 * @dialog_token: nonzero, identifies req/rsp transaction
150 * @elts[1]: Variable length information elements.
152 struct brcmf_p2p_pub_act_frame {
163 * struct brcmf_p2p_action_frame - WiFi P2P Action Frame
165 * @category: P2P_AF_CATEGORY
166 * @OUI[3]: OUI - P2P_OUI
167 * @type: OUI Type - P2P_VER
168 * @subtype: OUI Subtype - P2P_AF_*
169 * @dialog_token: nonzero, identifies req/resp tranaction
170 * @elts[1]: Variable length information elements.
172 struct brcmf_p2p_action_frame {
182 * struct brcmf_p2psd_gas_pub_act_frame - Wi-Fi GAS Public Action Frame
184 * @category: 0x04 Public Action Frame
185 * @action: 0x6c Advertisement Protocol
186 * @dialog_token: nonzero, identifies req/rsp transaction
187 * @query_data[1]: Query Data. SD gas ireq SD gas iresp
189 struct brcmf_p2psd_gas_pub_act_frame {
197 * struct brcmf_config_af_params - Action Frame Parameters for tx.
199 * @max_tx_retry: max tx retry count if tx no ack.
200 * @mpc_onoff: To make sure to send successfully action frame, we have to
201 * turn off mpc 0: off, 1: on, (-1): do nothing
203 struct brcmf_config_af_params {
209 * brcmf_p2p_is_pub_action() - true if p2p public type frame.
211 * @frame: action frame data.
212 * @frame_len: length of action frame data.
214 * Determine if action frame is p2p public action type
216 static bool brcmf_p2p_is_pub_action(void *frame, u32 frame_len)
218 struct brcmf_p2p_pub_act_frame *pact_frm;
223 pact_frm = (struct brcmf_p2p_pub_act_frame *)frame;
224 if (frame_len < sizeof(struct brcmf_p2p_pub_act_frame) - 1)
227 if (pact_frm->category == P2P_PUB_AF_CATEGORY &&
228 pact_frm->action == P2P_PUB_AF_ACTION &&
229 pact_frm->oui_type == P2P_VER &&
230 memcmp(pact_frm->oui, P2P_OUI, P2P_OUI_LEN) == 0)
237 * brcmf_p2p_is_p2p_action() - true if p2p action type frame.
239 * @frame: action frame data.
240 * @frame_len: length of action frame data.
242 * Determine if action frame is p2p action type
244 static bool brcmf_p2p_is_p2p_action(void *frame, u32 frame_len)
246 struct brcmf_p2p_action_frame *act_frm;
251 act_frm = (struct brcmf_p2p_action_frame *)frame;
252 if (frame_len < sizeof(struct brcmf_p2p_action_frame) - 1)
255 if (act_frm->category == P2P_AF_CATEGORY &&
256 act_frm->type == P2P_VER &&
257 memcmp(act_frm->oui, P2P_OUI, P2P_OUI_LEN) == 0)
264 * brcmf_p2p_is_gas_action() - true if p2p gas action type frame.
266 * @frame: action frame data.
267 * @frame_len: length of action frame data.
269 * Determine if action frame is p2p gas action type
271 static bool brcmf_p2p_is_gas_action(void *frame, u32 frame_len)
273 struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm;
278 sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame;
279 if (frame_len < sizeof(struct brcmf_p2psd_gas_pub_act_frame) - 1)
282 if (sd_act_frm->category != P2PSD_ACTION_CATEGORY)
285 if (sd_act_frm->action == P2PSD_ACTION_ID_GAS_IREQ ||
286 sd_act_frm->action == P2PSD_ACTION_ID_GAS_IRESP ||
287 sd_act_frm->action == P2PSD_ACTION_ID_GAS_CREQ ||
288 sd_act_frm->action == P2PSD_ACTION_ID_GAS_CRESP)
295 * brcmf_p2p_print_actframe() - debug print routine.
297 * @tx: Received or to be transmitted
298 * @frame: action frame data.
299 * @frame_len: length of action frame data.
301 * Print information about the p2p action frame
306 static void brcmf_p2p_print_actframe(bool tx, void *frame, u32 frame_len)
308 struct brcmf_p2p_pub_act_frame *pact_frm;
309 struct brcmf_p2p_action_frame *act_frm;
310 struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm;
312 if (!frame || frame_len <= 2)
315 if (brcmf_p2p_is_pub_action(frame, frame_len)) {
316 pact_frm = (struct brcmf_p2p_pub_act_frame *)frame;
317 switch (pact_frm->subtype) {
318 case P2P_PAF_GON_REQ:
319 brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Req Frame\n",
322 case P2P_PAF_GON_RSP:
323 brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Rsp Frame\n",
326 case P2P_PAF_GON_CONF:
327 brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Confirm Frame\n",
330 case P2P_PAF_INVITE_REQ:
331 brcmf_dbg(TRACE, "%s P2P Invitation Request Frame\n",
334 case P2P_PAF_INVITE_RSP:
335 brcmf_dbg(TRACE, "%s P2P Invitation Response Frame\n",
338 case P2P_PAF_DEVDIS_REQ:
339 brcmf_dbg(TRACE, "%s P2P Device Discoverability Request Frame\n",
342 case P2P_PAF_DEVDIS_RSP:
343 brcmf_dbg(TRACE, "%s P2P Device Discoverability Response Frame\n",
346 case P2P_PAF_PROVDIS_REQ:
347 brcmf_dbg(TRACE, "%s P2P Provision Discovery Request Frame\n",
350 case P2P_PAF_PROVDIS_RSP:
351 brcmf_dbg(TRACE, "%s P2P Provision Discovery Response Frame\n",
355 brcmf_dbg(TRACE, "%s Unknown P2P Public Action Frame\n",
359 } else if (brcmf_p2p_is_p2p_action(frame, frame_len)) {
360 act_frm = (struct brcmf_p2p_action_frame *)frame;
361 switch (act_frm->subtype) {
362 case P2P_AF_NOTICE_OF_ABSENCE:
363 brcmf_dbg(TRACE, "%s P2P Notice of Absence Frame\n",
366 case P2P_AF_PRESENCE_REQ:
367 brcmf_dbg(TRACE, "%s P2P Presence Request Frame\n",
370 case P2P_AF_PRESENCE_RSP:
371 brcmf_dbg(TRACE, "%s P2P Presence Response Frame\n",
374 case P2P_AF_GO_DISC_REQ:
375 brcmf_dbg(TRACE, "%s P2P Discoverability Request Frame\n",
379 brcmf_dbg(TRACE, "%s Unknown P2P Action Frame\n",
383 } else if (brcmf_p2p_is_gas_action(frame, frame_len)) {
384 sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame;
385 switch (sd_act_frm->action) {
386 case P2PSD_ACTION_ID_GAS_IREQ:
387 brcmf_dbg(TRACE, "%s P2P GAS Initial Request\n",
390 case P2PSD_ACTION_ID_GAS_IRESP:
391 brcmf_dbg(TRACE, "%s P2P GAS Initial Response\n",
394 case P2PSD_ACTION_ID_GAS_CREQ:
395 brcmf_dbg(TRACE, "%s P2P GAS Comback Request\n",
398 case P2PSD_ACTION_ID_GAS_CRESP:
399 brcmf_dbg(TRACE, "%s P2P GAS Comback Response\n",
403 brcmf_dbg(TRACE, "%s Unknown P2P GAS Frame\n",
412 static void brcmf_p2p_print_actframe(bool tx, void *frame, u32 frame_len)
419 * brcmf_p2p_set_firmware() - prepare firmware for peer-to-peer operation.
421 * @ifp: ifp to use for iovars (primary).
422 * @p2p_mac: mac address to configure for p2p_da_override
424 static int brcmf_p2p_set_firmware(struct brcmf_if *ifp, u8 *p2p_mac)
428 brcmf_fil_iovar_int_set(ifp, "apsta", 1);
430 /* In case of COB type, firmware has default mac address
431 * After Initializing firmware, we have to set current mac address to
432 * firmware for P2P device address
434 ret = brcmf_fil_iovar_data_set(ifp, "p2p_da_override", p2p_mac,
437 brcmf_err("failed to update device address ret %d\n", ret);
443 * brcmf_p2p_generate_bss_mac() - derive mac addresses for P2P.
445 * @p2p: P2P specific data.
447 * P2P needs mac addresses for P2P device and interface. These are
448 * derived from the primary net device, ie. the permanent ethernet
449 * address of the device.
451 static void brcmf_p2p_generate_bss_mac(struct brcmf_p2p_info *p2p)
453 struct brcmf_if *pri_ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
454 struct brcmf_if *p2p_ifp = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif->ifp;
456 /* Generate the P2P Device Address. This consists of the device's
457 * primary MAC address with the locally administered bit set.
459 memcpy(p2p->dev_addr, pri_ifp->mac_addr, ETH_ALEN);
460 p2p->dev_addr[0] |= 0x02;
461 memcpy(p2p_ifp->mac_addr, p2p->dev_addr, ETH_ALEN);
463 /* Generate the P2P Interface Address. If the discovery and connection
464 * BSSCFGs need to simultaneously co-exist, then this address must be
465 * different from the P2P Device Address, but also locally administered.
467 memcpy(p2p->int_addr, p2p->dev_addr, ETH_ALEN);
468 p2p->int_addr[4] ^= 0x80;
472 * brcmf_p2p_scan_is_p2p_request() - is cfg80211 scan request a P2P scan.
474 * @request: the scan request as received from cfg80211.
476 * returns true if one of the ssids in the request matches the
477 * P2P wildcard ssid; otherwise returns false.
479 static bool brcmf_p2p_scan_is_p2p_request(struct cfg80211_scan_request *request)
481 struct cfg80211_ssid *ssids = request->ssids;
484 for (i = 0; i < request->n_ssids; i++) {
485 if (ssids[i].ssid_len != BRCMF_P2P_WILDCARD_SSID_LEN)
488 brcmf_dbg(INFO, "comparing ssid \"%s\"", ssids[i].ssid);
489 if (!memcmp(BRCMF_P2P_WILDCARD_SSID, ssids[i].ssid,
490 BRCMF_P2P_WILDCARD_SSID_LEN))
497 * brcmf_p2p_set_discover_state - set discover state in firmware.
499 * @ifp: low-level interface object.
500 * @state: discover state to set.
501 * @chanspec: channel parameters (for state @WL_P2P_DISC_ST_LISTEN only).
502 * @listen_ms: duration to listen (for state @WL_P2P_DISC_ST_LISTEN only).
504 static s32 brcmf_p2p_set_discover_state(struct brcmf_if *ifp, u8 state,
505 u16 chanspec, u16 listen_ms)
507 struct brcmf_p2p_disc_st_le discover_state;
509 brcmf_dbg(TRACE, "enter\n");
511 discover_state.state = state;
512 discover_state.chspec = cpu_to_le16(chanspec);
513 discover_state.dwell = cpu_to_le16(listen_ms);
514 ret = brcmf_fil_bsscfg_data_set(ifp, "p2p_state", &discover_state,
515 sizeof(discover_state));
520 * brcmf_p2p_deinit_discovery() - disable P2P device discovery.
522 * @p2p: P2P specific data.
524 * Resets the discovery state and disables it in firmware.
526 static s32 brcmf_p2p_deinit_discovery(struct brcmf_p2p_info *p2p)
528 struct brcmf_cfg80211_vif *vif;
530 brcmf_dbg(TRACE, "enter\n");
532 /* Set the discovery state to SCAN */
533 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
534 (void)brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
536 /* Disable P2P discovery in the firmware */
537 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
538 (void)brcmf_fil_iovar_int_set(vif->ifp, "p2p_disc", 0);
544 * brcmf_p2p_enable_discovery() - initialize and configure discovery.
546 * @p2p: P2P specific data.
548 * Initializes the discovery device and configure the virtual interface.
550 static int brcmf_p2p_enable_discovery(struct brcmf_p2p_info *p2p)
552 struct brcmf_cfg80211_vif *vif;
555 brcmf_dbg(TRACE, "enter\n");
556 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
558 brcmf_err("P2P config device not available\n");
563 if (test_bit(BRCMF_P2P_STATUS_ENABLED, &p2p->status)) {
564 brcmf_dbg(INFO, "P2P config device already configured\n");
568 /* Re-initialize P2P Discovery in the firmware */
569 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
570 ret = brcmf_fil_iovar_int_set(vif->ifp, "p2p_disc", 1);
572 brcmf_err("set p2p_disc error\n");
575 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
576 ret = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
578 brcmf_err("unable to set WL_P2P_DISC_ST_SCAN\n");
583 * Set wsec to any non-zero value in the discovery bsscfg
584 * to ensure our P2P probe responses have the privacy bit
585 * set in the 802.11 WPA IE. Some peer devices may not
586 * initiate WPS with us if this bit is not set.
588 ret = brcmf_fil_bsscfg_int_set(vif->ifp, "wsec", AES_ENABLED);
590 brcmf_err("wsec error %d\n", ret);
594 set_bit(BRCMF_P2P_STATUS_ENABLED, &p2p->status);
600 * brcmf_p2p_escan() - initiate a P2P scan.
602 * @p2p: P2P specific data.
603 * @num_chans: number of channels to scan.
604 * @chanspecs: channel parameters for @num_chans channels.
605 * @search_state: P2P discover state to use.
606 * @action: scan action to pass to firmware.
607 * @bss_type: type of P2P bss.
609 static s32 brcmf_p2p_escan(struct brcmf_p2p_info *p2p, u32 num_chans,
610 u16 chanspecs[], s32 search_state, u16 action,
611 enum p2p_bss_type bss_type)
614 s32 memsize = offsetof(struct brcmf_p2p_scan_le,
615 eparams.params_le.channel_list);
620 struct brcmf_cfg80211_vif *vif;
621 struct brcmf_p2p_scan_le *p2p_params;
622 struct brcmf_scan_params_le *sparams;
623 struct brcmf_ssid ssid;
625 memsize += num_chans * sizeof(__le16);
626 memblk = kzalloc(memsize, GFP_KERNEL);
630 vif = p2p->bss_idx[bss_type].vif;
632 brcmf_err("no vif for bss type %d\n", bss_type);
637 switch (search_state) {
638 case WL_P2P_DISC_ST_SEARCH:
640 * If we in SEARCH STATE, we don't need to set SSID explictly
641 * because dongle use P2P WILDCARD internally by default
645 memset(ssid.SSID, 0, sizeof(ssid.SSID));
647 case WL_P2P_DISC_ST_SCAN:
649 * wpa_supplicant has p2p_find command with type social or
650 * progressive. For progressive, we need to set the ssid to
651 * P2P WILDCARD because we just do broadcast scan unless
654 ssid.SSID_len = BRCMF_P2P_WILDCARD_SSID_LEN;
655 memcpy(ssid.SSID, BRCMF_P2P_WILDCARD_SSID, ssid.SSID_len);
658 brcmf_err(" invalid search state %d\n", search_state);
663 brcmf_p2p_set_discover_state(vif->ifp, search_state, 0, 0);
666 * set p2p scan parameters.
668 p2p_params = (struct brcmf_p2p_scan_le *)memblk;
669 p2p_params->type = 'E';
671 /* determine the scan engine parameters */
672 sparams = &p2p_params->eparams.params_le;
673 sparams->bss_type = DOT11_BSSTYPE_ANY;
674 if (p2p->cfg->active_scan)
675 sparams->scan_type = 0;
677 sparams->scan_type = 1;
679 memset(&sparams->bssid, 0xFF, ETH_ALEN);
681 memcpy(sparams->ssid_le.SSID, ssid.SSID, ssid.SSID_len);
682 sparams->ssid_le.SSID_len = cpu_to_le32(ssid.SSID_len);
683 sparams->home_time = cpu_to_le32(P2PAPI_SCAN_HOME_TIME_MS);
686 * SOCIAL_CHAN_CNT + 1 takes care of the Progressive scan
687 * supported by the supplicant.
689 if (num_chans == SOCIAL_CHAN_CNT || num_chans == (SOCIAL_CHAN_CNT + 1))
690 active = P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS;
691 else if (num_chans == AF_PEER_SEARCH_CNT)
692 active = P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS;
693 else if (wl_get_vif_state_all(p2p->cfg, BRCMF_VIF_STATUS_CONNECTED))
696 active = P2PAPI_SCAN_DWELL_TIME_MS;
698 /* Override scan params to find a peer for a connection */
699 if (num_chans == 1) {
700 active = WL_SCAN_CONNECT_DWELL_TIME_MS;
701 /* WAR to sync with presence period of VSDB GO.
702 * send probe request more frequently
704 nprobes = active / WL_SCAN_JOIN_PROBE_INTERVAL_MS;
706 nprobes = active / P2PAPI_SCAN_NPROBS_TIME_MS;
712 brcmf_dbg(INFO, "nprobes # %d, active_time %d\n", nprobes, active);
713 sparams->active_time = cpu_to_le32(active);
714 sparams->nprobes = cpu_to_le32(nprobes);
715 sparams->passive_time = cpu_to_le32(-1);
716 sparams->channel_num = cpu_to_le32(num_chans &
717 BRCMF_SCAN_PARAMS_COUNT_MASK);
718 for (i = 0; i < num_chans; i++)
719 sparams->channel_list[i] = cpu_to_le16(chanspecs[i]);
721 /* set the escan specific parameters */
722 p2p_params->eparams.version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION);
723 p2p_params->eparams.action = cpu_to_le16(action);
724 p2p_params->eparams.sync_id = cpu_to_le16(0x1234);
725 /* perform p2p scan on primary device */
726 ret = brcmf_fil_bsscfg_data_set(vif->ifp, "p2p_scan", memblk, memsize);
728 set_bit(BRCMF_SCAN_STATUS_BUSY, &p2p->cfg->scan_status);
735 * brcmf_p2p_run_escan() - escan callback for peer-to-peer.
737 * @cfg: driver private data for cfg80211 interface.
738 * @ndev: net device for which scan is requested.
739 * @request: scan request from cfg80211.
740 * @action: scan action.
742 * Determines the P2P discovery state based to scan request parameters and
743 * validates the channels in the request.
745 static s32 brcmf_p2p_run_escan(struct brcmf_cfg80211_info *cfg,
746 struct net_device *ndev,
747 struct cfg80211_scan_request *request,
750 struct brcmf_p2p_info *p2p = &cfg->p2p;
752 s32 search_state = WL_P2P_DISC_ST_SCAN;
753 struct brcmf_cfg80211_vif *vif;
754 struct net_device *dev = NULL;
755 int i, num_nodfs = 0;
758 brcmf_dbg(TRACE, "enter\n");
765 if (request->n_channels) {
766 chanspecs = kcalloc(request->n_channels, sizeof(*chanspecs),
772 vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
774 dev = vif->wdev.netdev;
775 if (request->n_channels == 3 &&
776 request->channels[0]->hw_value == SOCIAL_CHAN_1 &&
777 request->channels[1]->hw_value == SOCIAL_CHAN_2 &&
778 request->channels[2]->hw_value == SOCIAL_CHAN_3) {
779 /* SOCIAL CHANNELS 1, 6, 11 */
780 search_state = WL_P2P_DISC_ST_SEARCH;
781 brcmf_dbg(INFO, "P2P SEARCH PHASE START\n");
782 } else if (dev != NULL && vif->mode == WL_MODE_AP) {
783 /* If you are already a GO, then do SEARCH only */
784 brcmf_dbg(INFO, "Already a GO. Do SEARCH Only\n");
785 search_state = WL_P2P_DISC_ST_SEARCH;
787 brcmf_dbg(INFO, "P2P SCAN STATE START\n");
791 * no P2P scanning on passive or DFS channels.
793 for (i = 0; i < request->n_channels; i++) {
794 struct ieee80211_channel *chan = request->channels[i];
796 if (chan->flags & (IEEE80211_CHAN_RADAR |
797 IEEE80211_CHAN_PASSIVE_SCAN))
800 chanspecs[i] = channel_to_chanspec(chan);
801 brcmf_dbg(INFO, "%d: chan=%d, channel spec=%x\n",
802 num_nodfs, chan->hw_value, chanspecs[i]);
805 err = brcmf_p2p_escan(p2p, num_nodfs, chanspecs, search_state,
806 action, P2PAPI_BSSCFG_DEVICE);
810 brcmf_err("error (%d)\n", err);
815 * brcmf_p2p_scan_prep() - prepare scan based on request.
817 * @wiphy: wiphy device.
818 * @request: scan request from cfg80211.
819 * @vif: vif on which scan request is to be executed.
821 * Prepare the scan appropriately for type of scan requested. Overrides the
822 * escan .run() callback for peer-to-peer scanning.
824 int brcmf_p2p_scan_prep(struct wiphy *wiphy,
825 struct cfg80211_scan_request *request,
826 struct brcmf_cfg80211_vif *vif)
828 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
829 struct brcmf_p2p_info *p2p = &cfg->p2p;
832 if (brcmf_p2p_scan_is_p2p_request(request)) {
833 /* find my listen channel */
834 err = cfg80211_get_p2p_attr(request->ie, request->ie_len,
835 IEEE80211_P2P_ATTR_LISTEN_CHANNEL,
836 &p2p->listen_channel, 1);
840 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
841 brcmf_dbg(INFO, "P2P: GO_NEG_PHASE status cleared\n");
843 err = brcmf_p2p_enable_discovery(p2p);
847 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
849 /* override .run_escan() callback. */
850 cfg->escan_info.run = brcmf_p2p_run_escan;
852 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBREQ_FLAG,
853 request->ie, request->ie_len);
859 * brcmf_p2p_discover_listen() - set firmware to discover listen state.
862 * @freq: center frequency for discover listen.
863 * #@duration: time in ms to stay on channel.
867 brcmf_p2p_discover_listen(struct brcmf_p2p_info *p2p,
868 struct ieee80211_channel *channel, u32 duration)
870 struct brcmf_cfg80211_vif *vif;
874 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
876 brcmf_err("Discovery is not set, so we have nothing to do\n");
881 if (test_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status)) {
882 brcmf_err("Previous LISTEN is not completed yet\n");
883 /* WAR: prevent cookie mismatch in wpa_supplicant return OK */
887 chanspec = channel_to_chanspec(channel);
888 err = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_LISTEN,
889 chanspec, (u16)duration);
891 set_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status);
892 p2p->remain_on_channel_cookie++;
900 * brcmf_p2p_remain_on_channel() - put device on channel and stay there.
902 * @wiphy: wiphy device.
903 * @channel: channel to stay on.
904 * @duration: time in ms to remain on channel.
907 int brcmf_p2p_remain_on_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
908 struct ieee80211_channel *channel,
909 unsigned int duration, u64 *cookie)
911 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
912 struct brcmf_p2p_info *p2p = &cfg->p2p;
915 brcmf_dbg(TRACE, "Enter, channel: %d, duration ms (%d)\n",
916 ieee80211_frequency_to_channel(channel->center_freq),
919 err = brcmf_p2p_enable_discovery(p2p);
922 err = brcmf_p2p_discover_listen(p2p, channel, duration);
926 memcpy(&p2p->remain_on_channel, channel, sizeof(*channel));
927 *cookie = p2p->remain_on_channel_cookie;
928 cfg80211_ready_on_channel(wdev, *cookie, channel, duration, GFP_KERNEL);
936 * brcmf_p2p_notify_listen_complete() - p2p listen has completed.
938 * @ifp: interfac control.
939 * @e: event message. Not used, to make it usable for fweh event dispatcher.
940 * @data: payload of message. Not used.
943 int brcmf_p2p_notify_listen_complete(struct brcmf_if *ifp,
944 const struct brcmf_event_msg *e,
947 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
948 struct brcmf_p2p_info *p2p = &cfg->p2p;
950 brcmf_dbg(TRACE, "Enter\n");
951 if (test_and_clear_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN,
953 cfg80211_remain_on_channel_expired(&ifp->vif->wdev,
954 p2p->remain_on_channel_cookie,
955 &p2p->remain_on_channel,
962 * brcmf_p2p_cancel_remain_on_channel() - cancel p2p listen state.
964 * @ifp: interfac control.
967 void brcmf_p2p_cancel_remain_on_channel(struct brcmf_if *ifp)
971 brcmf_p2p_set_discover_state(ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
972 brcmf_p2p_notify_listen_complete(ifp, NULL, NULL);
977 * brcmf_p2p_notify_action_frame_rx() - received action frame.
979 * @ifp: interfac control.
980 * @e: event message. Not used, to make it usable for fweh event dispatcher.
981 * @data: payload of message, containing action frame data.
984 int brcmf_p2p_notify_action_frame_rx(struct brcmf_if *ifp,
985 const struct brcmf_event_msg *e,
988 struct wireless_dev *wdev;
989 u32 mgmt_frame_len = e->datalen - sizeof(struct brcmf_rx_mgmt_data);
990 struct brcmf_rx_mgmt_data *rxframe = (struct brcmf_rx_mgmt_data *)data;
991 u16 chanspec = be16_to_cpu(rxframe->chanspec);
992 struct ieee80211_mgmt *mgmt_frame;
997 /* Check if wpa_supplicant has registered for this frame */
998 brcmf_dbg(INFO, "ifp->vif->mgmt_rx_reg %04x\n", ifp->vif->mgmt_rx_reg);
999 mgmt_type = (IEEE80211_STYPE_ACTION & IEEE80211_FCTL_STYPE) >> 4;
1000 if ((ifp->vif->mgmt_rx_reg & BIT(mgmt_type)) == 0)
1003 brcmf_p2p_print_actframe(false, (u8 *)(rxframe + 1), mgmt_frame_len);
1005 mgmt_frame = kzalloc(offsetof(struct ieee80211_mgmt, u) +
1006 mgmt_frame_len, GFP_KERNEL);
1008 brcmf_err("No memory available for action frame\n");
1011 memcpy(mgmt_frame->da, ifp->mac_addr, ETH_ALEN);
1012 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSSID, mgmt_frame->bssid,
1015 brcmf_err("BRCMF_C_GET_BSSID error %d\n", err);
1016 memcpy(mgmt_frame->sa, e->addr, ETH_ALEN);
1017 mgmt_frame->frame_control = cpu_to_le16(IEEE80211_STYPE_ACTION);
1018 memcpy(&mgmt_frame->u, (u8 *)(rxframe + 1), mgmt_frame_len);
1019 mgmt_frame_len += offsetof(struct ieee80211_mgmt, u);
1021 freq = ieee80211_channel_to_frequency(CHSPEC_CHANNEL(chanspec),
1022 CHSPEC_IS2G(chanspec) ?
1023 IEEE80211_BAND_2GHZ :
1024 IEEE80211_BAND_5GHZ);
1025 wdev = ifp->ndev->ieee80211_ptr;
1026 cfg80211_rx_mgmt(wdev, freq, 0, (u8 *)mgmt_frame, mgmt_frame_len,
1035 * brcmf_p2p_notify_action_tx_complete() - transmit action frame complete
1037 * @ifp: interfac control.
1038 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1042 int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp,
1043 const struct brcmf_event_msg *e,
1046 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
1047 struct brcmf_p2p_info *p2p = &cfg->p2p;
1049 brcmf_dbg(INFO, "Enter: status %d\n", e->status);
1051 if (e->status == BRCMF_E_STATUS_SUCCESS)
1052 set_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
1054 set_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
1055 /* for now complete the receiver process here !! */
1056 complete(&p2p->send_af_done);
1063 * brcmf_p2p_tx_action_frame() - send action frame over fil.
1065 * @p2p: p2p info struct for vif.
1066 * @af_params: action frame data/info.
1068 * Send an action frame immediately without doing channel synchronization.
1070 * This function waits for a completion event before returning.
1071 * The WLC_E_ACTION_FRAME_COMPLETE event will be received when the action
1072 * frame is transmitted.
1074 static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p,
1075 struct brcmf_fil_af_params_le *af_params)
1077 struct brcmf_cfg80211_vif *vif;
1081 brcmf_dbg(TRACE, "Enter\n");
1083 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
1084 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
1086 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
1087 err = brcmf_fil_bsscfg_data_set(vif->ifp, "actframe", af_params,
1088 sizeof(*af_params));
1090 brcmf_err(" sending action frame has failed\n");
1094 timeout = wait_for_completion_timeout(&p2p->send_af_done,
1095 msecs_to_jiffies(P2P_AF_MAX_WAIT_TIME));
1097 if (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status)) {
1098 brcmf_dbg(TRACE, "TX action frame operation is success\n");
1101 brcmf_dbg(TRACE, "TX action frame operation has failed\n");
1103 /* clear status bit for action tx */
1104 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
1105 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
1113 * brcmf_p2p_pub_af_tx() - public action frame tx routine.
1115 * @cfg: driver private data for cfg80211 interface.
1116 * @af_params: action frame data/info.
1117 * @config_af_params: configuration data for action frame.
1119 * routine which transmits ation frame public type.
1121 static s32 brcmf_p2p_pub_af_tx(struct brcmf_cfg80211_info *cfg,
1122 struct brcmf_fil_af_params_le *af_params,
1123 struct brcmf_config_af_params *config_af_params)
1125 struct brcmf_p2p_info *p2p = &cfg->p2p;
1126 struct brcmf_fil_action_frame_le *action_frame;
1127 struct brcmf_p2p_pub_act_frame *act_frm;
1130 action_frame = &af_params->action_frame;
1131 act_frm = (struct brcmf_p2p_pub_act_frame *)(action_frame->data);
1133 switch (act_frm->subtype) {
1134 case P2P_PAF_GON_REQ:
1135 brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status set\n");
1136 set_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
1137 config_af_params->mpc_onoff = 0;
1138 p2p->next_af_subtype = act_frm->subtype + 1;
1139 /* increase dwell time to wait for RESP frame */
1140 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1142 case P2P_PAF_GON_RSP:
1143 p2p->next_af_subtype = act_frm->subtype + 1;
1144 /* increase dwell time to wait for CONF frame */
1145 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1147 case P2P_PAF_GON_CONF:
1148 /* If we reached till GO Neg confirmation reset the filter */
1149 brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status cleared\n");
1150 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
1151 /* turn on mpc again if go nego is done */
1152 config_af_params->mpc_onoff = 1;
1153 /* minimize dwell time */
1154 af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1156 case P2P_PAF_INVITE_REQ:
1157 p2p->next_af_subtype = act_frm->subtype + 1;
1158 /* increase dwell time */
1159 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1161 case P2P_PAF_INVITE_RSP:
1162 /* minimize dwell time */
1163 af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1165 case P2P_PAF_DEVDIS_REQ:
1166 p2p->next_af_subtype = act_frm->subtype + 1;
1167 /* maximize dwell time to wait for RESP frame */
1168 af_params->dwell_time = cpu_to_le32(P2P_AF_LONG_DWELL_TIME);
1170 case P2P_PAF_DEVDIS_RSP:
1171 /* minimize dwell time */
1172 af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1174 case P2P_PAF_PROVDIS_REQ:
1175 config_af_params->mpc_onoff = 0;
1176 p2p->next_af_subtype = act_frm->subtype + 1;
1177 /* increase dwell time to wait for RESP frame */
1178 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1180 case P2P_PAF_PROVDIS_RSP:
1181 /* wpa_supplicant send go nego req right after prov disc */
1182 p2p->next_af_subtype = P2P_PAF_GON_REQ;
1183 /* increase dwell time to MED level */
1184 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1187 brcmf_err("Unknown p2p pub act frame subtype: %d\n",
1195 * brcmf_p2p_send_action_frame() - send action frame .
1197 * @cfg: driver private data for cfg80211 interface.
1198 * @ndev: net device to transmit on.
1199 * @af_params: configuration data for action frame.
1201 bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info *cfg,
1202 struct net_device *ndev,
1203 struct brcmf_fil_af_params_le *af_params)
1205 struct brcmf_p2p_info *p2p = &cfg->p2p;
1206 struct brcmf_fil_action_frame_le *action_frame;
1207 struct brcmf_config_af_params config_af_params;
1208 u16 action_frame_len;
1214 action_frame = &af_params->action_frame;
1215 action_frame_len = le16_to_cpu(action_frame->len);
1217 brcmf_p2p_print_actframe(true, action_frame->data, action_frame_len);
1219 /* Add the default dwell time. Dwell time to stay off-channel */
1220 /* to wait for a response action frame after transmitting an */
1221 /* GO Negotiation action frame */
1222 af_params->dwell_time = cpu_to_le32(P2P_AF_DWELL_TIME);
1224 category = action_frame->data[DOT11_ACTION_CAT_OFF];
1225 action = action_frame->data[DOT11_ACTION_ACT_OFF];
1227 /* initialize variables */
1228 p2p->next_af_subtype = P2P_PAF_SUBTYPE_INVALID;
1230 /* config parameters */
1231 config_af_params.max_tx_retry = P2P_AF_TX_MAX_RETRY;
1232 config_af_params.mpc_onoff = -1;
1234 if (brcmf_p2p_is_pub_action(action_frame->data, action_frame_len)) {
1235 /* p2p public action frame process */
1236 if (brcmf_p2p_pub_af_tx(cfg, af_params, &config_af_params)) {
1237 /* Just send unknown subtype frame with */
1238 /* default parameters. */
1239 brcmf_err("P2P Public action frame, unknown subtype.\n");
1241 } else if (brcmf_p2p_is_gas_action(action_frame->data,
1242 action_frame_len)) {
1243 /* service discovery process */
1244 if (action == P2PSD_ACTION_ID_GAS_IREQ ||
1245 action == P2PSD_ACTION_ID_GAS_CREQ) {
1246 /* save next af suptype to cancel */
1247 /* remaining dwell time */
1248 p2p->next_af_subtype = action + 1;
1250 af_params->dwell_time =
1251 cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1252 } else if (action == P2PSD_ACTION_ID_GAS_IRESP ||
1253 action == P2PSD_ACTION_ID_GAS_CRESP) {
1254 /* configure service discovery response frame */
1255 af_params->dwell_time =
1256 cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1258 brcmf_err("Unknown action type: %d\n", action);
1261 } else if (brcmf_p2p_is_p2p_action(action_frame->data,
1262 action_frame_len)) {
1263 /* do not configure anything. it will be */
1264 /* sent with a default configuration */
1266 brcmf_err("Unknown Frame: category 0x%x, action 0x%x\n",
1271 /* if scan is ongoing, abort current scan. */
1272 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
1273 brcmf_abort_scanning(cfg);
1275 /* To make sure to send successfully action frame, turn off mpc */
1276 if (config_af_params.mpc_onoff == 0)
1277 brcmf_set_mpc(ndev, 0);
1279 /* if failed, retry it. tx_retry_max value is configure by .... */
1281 while ((ack == false) && (tx_retry < config_af_params.max_tx_retry)) {
1282 ack = !brcmf_p2p_tx_action_frame(p2p, af_params);
1286 brcmf_err("Failed to send Action Frame(retry %d)\n", tx_retry);
1289 /* if all done, turn mpc on again */
1290 if (config_af_params.mpc_onoff == 1)
1291 brcmf_set_mpc(ndev, 1);
1298 * brcmf_p2p_attach() - attach for P2P.
1300 * @cfg: driver private data for cfg80211 interface.
1302 s32 brcmf_p2p_attach(struct brcmf_cfg80211_info *cfg)
1304 struct brcmf_if *pri_ifp;
1305 struct brcmf_if *p2p_ifp;
1306 struct brcmf_cfg80211_vif *p2p_vif;
1307 struct brcmf_p2p_info *p2p;
1308 struct brcmf_pub *drvr;
1317 pri_ifp = drvr->iflist[0];
1318 p2p_ifp = drvr->iflist[1];
1320 p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif = pri_ifp->vif;
1323 p2p_vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION,
1325 if (IS_ERR(p2p_vif)) {
1326 brcmf_err("could not create discovery vif\n");
1331 p2p_vif->ifp = p2p_ifp;
1332 p2p_ifp->vif = p2p_vif;
1333 p2p_vif->wdev.netdev = p2p_ifp->ndev;
1334 p2p_ifp->ndev->ieee80211_ptr = &p2p_vif->wdev;
1335 SET_NETDEV_DEV(p2p_ifp->ndev, wiphy_dev(cfg->wiphy));
1337 p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif = p2p_vif;
1339 brcmf_p2p_generate_bss_mac(p2p);
1340 brcmf_p2p_set_firmware(pri_ifp, p2p->dev_addr);
1342 /* Initialize P2P Discovery in the firmware */
1343 err = brcmf_fil_iovar_int_set(pri_ifp, "p2p_disc", 1);
1345 brcmf_err("set p2p_disc error\n");
1346 brcmf_free_vif(p2p_vif);
1349 /* obtain bsscfg index for P2P discovery */
1350 err = brcmf_fil_iovar_int_get(pri_ifp, "p2p_dev", &bssidx);
1352 brcmf_err("retrieving discover bsscfg index failed\n");
1353 brcmf_free_vif(p2p_vif);
1356 /* Verify that firmware uses same bssidx as driver !! */
1357 if (p2p_ifp->bssidx != bssidx) {
1358 brcmf_err("Incorrect bssidx=%d, compared to p2p_ifp->bssidx=%d\n",
1359 bssidx, p2p_ifp->bssidx);
1360 brcmf_free_vif(p2p_vif);
1364 init_completion(&p2p->send_af_done);
1372 * brcmf_p2p_detach() - detach P2P.
1374 * @p2p: P2P specific data.
1376 void brcmf_p2p_detach(struct brcmf_p2p_info *p2p)
1378 struct brcmf_cfg80211_vif *vif;
1380 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
1382 brcmf_p2p_cancel_remain_on_channel(vif->ifp);
1383 brcmf_p2p_deinit_discovery(p2p);
1384 /* remove discovery interface */
1385 brcmf_free_vif(vif);
1386 p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif = NULL;
1388 /* just set it all to zero */
1389 memset(p2p, 0, sizeof(*p2p));
1393 * brcmf_p2p_get_current_chanspec() - Get current operation channel.
1395 * @p2p: P2P specific data.
1396 * @chanspec: chanspec to be returned.
1398 static void brcmf_p2p_get_current_chanspec(struct brcmf_p2p_info *p2p,
1401 struct brcmf_if *ifp;
1402 struct brcmf_fil_chan_info_le ci;
1405 ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
1407 *chanspec = 11 & WL_CHANSPEC_CHAN_MASK;
1409 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_CHANNEL, &ci, sizeof(ci));
1411 *chanspec = le32_to_cpu(ci.hw_channel) & WL_CHANSPEC_CHAN_MASK;
1412 if (*chanspec < CH_MAX_2G_CHANNEL)
1413 *chanspec |= WL_CHANSPEC_BAND_2G;
1415 *chanspec |= WL_CHANSPEC_BAND_5G;
1417 *chanspec |= WL_CHANSPEC_BW_20 | WL_CHANSPEC_CTL_SB_NONE;
1421 * Change a P2P Role.
1423 * @mac: MAC address of the BSS to change a role
1424 * Returns 0 if success.
1426 int brcmf_p2p_ifchange(struct brcmf_cfg80211_info *cfg,
1427 enum brcmf_fil_p2p_if_types if_type)
1429 struct brcmf_p2p_info *p2p = &cfg->p2p;
1430 struct brcmf_cfg80211_vif *vif;
1431 struct brcmf_fil_p2p_if_le if_request;
1435 brcmf_dbg(TRACE, "Enter\n");
1437 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
1439 brcmf_err("vif for P2PAPI_BSSCFG_PRIMARY does not exist\n");
1442 brcmf_notify_escan_complete(cfg, vif->ifp->ndev, true, true);
1443 vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
1445 brcmf_err("vif for P2PAPI_BSSCFG_CONNECTION does not exist\n");
1448 brcmf_set_mpc(vif->ifp->ndev, 0);
1450 /* In concurrency case, STA may be already associated in a particular */
1451 /* channel. so retrieve the current channel of primary interface and */
1452 /* then start the virtual interface on that. */
1453 brcmf_p2p_get_current_chanspec(p2p, &chanspec);
1455 if_request.type = cpu_to_le16((u16)if_type);
1456 if_request.chspec = cpu_to_le16(chanspec);
1457 memcpy(if_request.addr, p2p->int_addr, sizeof(if_request.addr));
1459 brcmf_cfg80211_arm_vif_event(cfg, vif);
1460 err = brcmf_fil_iovar_data_set(vif->ifp, "p2p_ifupd", &if_request,
1461 sizeof(if_request));
1463 brcmf_err("p2p_ifupd FAILED, err=%d\n", err);
1464 brcmf_cfg80211_arm_vif_event(cfg, NULL);
1467 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_CHANGE,
1468 msecs_to_jiffies(1500));
1469 brcmf_cfg80211_arm_vif_event(cfg, NULL);
1471 brcmf_err("No BRCMF_E_IF_CHANGE event received\n");
1475 err = brcmf_fil_cmd_int_set(vif->ifp, BRCMF_C_SET_SCB_TIMEOUT,
1476 BRCMF_SCB_TIMEOUT_VALUE);
1481 static int brcmf_p2p_request_p2p_if(struct brcmf_p2p_info *p2p,
1482 struct brcmf_if *ifp, u8 ea[ETH_ALEN],
1483 enum brcmf_fil_p2p_if_types iftype)
1485 struct brcmf_fil_p2p_if_le if_request;
1489 /* we need a default channel */
1490 brcmf_p2p_get_current_chanspec(p2p, &chanspec);
1492 /* fill the firmware request */
1493 memcpy(if_request.addr, ea, ETH_ALEN);
1494 if_request.type = cpu_to_le16((u16)iftype);
1495 if_request.chspec = cpu_to_le16(chanspec);
1497 err = brcmf_fil_iovar_data_set(ifp, "p2p_ifadd", &if_request,
1498 sizeof(if_request));
1505 static int brcmf_p2p_disable_p2p_if(struct brcmf_cfg80211_vif *vif)
1507 struct brcmf_cfg80211_info *cfg = wdev_to_cfg(&vif->wdev);
1508 struct net_device *pri_ndev = cfg_to_ndev(cfg);
1509 struct brcmf_if *ifp = netdev_priv(pri_ndev);
1510 u8 *addr = vif->wdev.netdev->dev_addr;
1512 return brcmf_fil_iovar_data_set(ifp, "p2p_ifdis", addr, ETH_ALEN);
1515 static int brcmf_p2p_release_p2p_if(struct brcmf_cfg80211_vif *vif)
1517 struct brcmf_cfg80211_info *cfg = wdev_to_cfg(&vif->wdev);
1518 struct net_device *pri_ndev = cfg_to_ndev(cfg);
1519 struct brcmf_if *ifp = netdev_priv(pri_ndev);
1520 u8 *addr = vif->wdev.netdev->dev_addr;
1522 return brcmf_fil_iovar_data_set(ifp, "p2p_ifdel", addr, ETH_ALEN);
1526 * brcmf_p2p_add_vif() - create a new P2P virtual interface.
1528 * @wiphy: wiphy device of new interface.
1529 * @name: name of the new interface.
1530 * @type: nl80211 interface type.
1534 struct wireless_dev *brcmf_p2p_add_vif(struct wiphy *wiphy, const char *name,
1535 enum nl80211_iftype type, u32 *flags,
1536 struct vif_params *params)
1538 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
1539 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
1540 struct brcmf_cfg80211_vif *vif;
1541 enum brcmf_fil_p2p_if_types iftype;
1545 if (brcmf_cfg80211_vif_event_armed(cfg))
1546 return ERR_PTR(-EBUSY);
1548 brcmf_dbg(INFO, "adding vif \"%s\" (type=%d)\n", name, type);
1551 case NL80211_IFTYPE_P2P_CLIENT:
1552 iftype = BRCMF_FIL_P2P_IF_CLIENT;
1555 case NL80211_IFTYPE_P2P_GO:
1556 iftype = BRCMF_FIL_P2P_IF_GO;
1560 return ERR_PTR(-EOPNOTSUPP);
1563 vif = brcmf_alloc_vif(cfg, type, false);
1565 return (struct wireless_dev *)vif;
1566 brcmf_cfg80211_arm_vif_event(cfg, vif);
1568 err = brcmf_p2p_request_p2p_if(&cfg->p2p, ifp, cfg->p2p.int_addr,
1571 brcmf_cfg80211_arm_vif_event(cfg, NULL);
1575 /* wait for firmware event */
1576 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_ADD,
1577 msecs_to_jiffies(1500));
1578 brcmf_cfg80211_arm_vif_event(cfg, NULL);
1580 brcmf_err("timeout occurred\n");
1585 /* interface created in firmware */
1588 brcmf_err("no if pointer provided\n");
1593 strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1);
1594 brcmf_cfg80211_vif_complete(cfg);
1595 cfg->p2p.bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = vif;
1596 /* Disable firmware roaming for P2P interface */
1597 brcmf_fil_iovar_int_set(ifp, "roam_off", 1);
1598 if (iftype == BRCMF_FIL_P2P_IF_GO) {
1599 /* set station timeout for p2p */
1600 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCB_TIMEOUT,
1601 BRCMF_SCB_TIMEOUT_VALUE);
1603 return &ifp->vif->wdev;
1606 brcmf_free_vif(vif);
1607 return ERR_PTR(err);
1611 * brcmf_p2p_del_vif() - delete a P2P virtual interface.
1613 * @wiphy: wiphy device of interface.
1614 * @wdev: wireless device of interface.
1616 * TODO: not yet supported.
1618 int brcmf_p2p_del_vif(struct wiphy *wiphy, struct wireless_dev *wdev)
1620 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
1621 struct brcmf_cfg80211_vif *vif;
1622 unsigned long jiffie_timeout = msecs_to_jiffies(1500);
1623 bool wait_for_disable = false;
1626 brcmf_dbg(TRACE, "delete P2P vif\n");
1627 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
1629 switch (vif->wdev.iftype) {
1630 case NL80211_IFTYPE_P2P_CLIENT:
1631 if (test_bit(BRCMF_VIF_STATUS_DISCONNECTING, &vif->sme_state))
1632 wait_for_disable = true;
1635 case NL80211_IFTYPE_P2P_GO:
1636 if (!brcmf_p2p_disable_p2p_if(vif))
1637 wait_for_disable = true;
1640 case NL80211_IFTYPE_P2P_DEVICE:
1646 if (wait_for_disable)
1647 wait_for_completion_timeout(&cfg->vif_disabled,
1648 msecs_to_jiffies(500));
1650 brcmf_vif_clear_mgmt_ies(vif);
1652 brcmf_cfg80211_arm_vif_event(cfg, vif);
1653 err = brcmf_p2p_release_p2p_if(vif);
1655 /* wait for firmware event */
1656 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_DEL,
1663 brcmf_cfg80211_arm_vif_event(cfg, NULL);
1664 brcmf_free_vif(vif);
1665 cfg->p2p.bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = NULL;